الانتقال إلى المحتوى
View in the app

A better way to browse. Learn more.

مجموعة مستخدمي أوراكل العربية

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

كيف اعمل تحميل لصورة على السيرفر

Featured Replies

بتاريخ:

السلام عليكم
عندى شاشة فيها بيانات الموظف فيها ايضا صورة الموظف
اريد ان اجعل المستخدم يختار الصورة من على جهازه ثم يقوم النظام بتحميلها على السرفر فى مجلد خاص به صور الموظفين

قمت بعمل التالي
1- استخدمت af:inputFile كالتالي

						    <af:inputFile id="if1"
										  label="#{viewcontrollerBundle.UPLOAD_PHOTO_FOR} #{bindings.EmpNum}"
										  value="#{backingBeanScope.basicInfo.file}" autoSubmit="true"/>


و بالطبع عملت bean و وضغتها فى ال backingBeanScope
2- كتبت فى الكلاس الكود التالي

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.InputStream;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.imageio.ImageIO;
import javax.servlet.ServletContext;
import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.model.binding.DCIteratorBinding;
import oracle.binding.AttributeBinding;
import oracle.binding.BindingContainer;
import oracle.binding.OperationBinding;
import oracle.jbo.Row;
import org.apache.myfaces.trinidad.model.UploadedFile;
import oracle.jbo.domain.Number;
public class BasicInfo {
   private UploadedFile _file;
   public UploadedFile getFile() {
    return _file;
   }
   public void setFile(UploadedFile file) {
    _file = file;
   }
   public String processUpload() {
    UploadedFile myfile = this.getFile();
    FacesContext fctx = FacesContext.getCurrentInstance();
    ServletContext servletCtx =
	    (ServletContext)fctx.getExternalContext().getContext();
    String imageDirPath = servletCtx.getRealPath("/");
    try {
	    InputStream inputStream = myfile.getInputStream();
	    BufferedImage input = ImageIO.read(inputStream);
	    File outputFile =
		    new File(imageDirPath + "/images/" + this.getCurrentEmployeeId()+".png");		
	    ImageIO.write(input, "PNG", outputFile);
	   
    } catch (Exception ex) {
	    // handle exception
    }
    FacesMessage message =
	    new FacesMessage("Successfully uploaded file " + myfile.getFilename() +
						 " (" + myfile.getLength() + " bytes)");
    fctx.addMessage(null, message);
    return null;
   }
   public Number getCurrentEmployeeId(){
    BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
    AttributeBinding attr = (AttributeBinding)bindings.getControlBinding("EmpNum");
   
    return (Number)attr.getInputValue();
    }
  


3- قمت باضافة command button على الصفحة كالتالي

						   <af:commandButton text="#{viewcontrollerBundle.PROCESS}" id="cb1"
											  action="#{backingBeanScope.basicInfo.processUpload}"/>


4- فى ال af:form قمت بتغير قيمة useUpload = true

<af:form id="f1" usesUpload="true">


5- , hodvh tn lgt صثلامخلهؤزءةم rlj fhgju]dg hgjhgd

 <native-io-enabled>true</native-io-enabled>
   <show-archived-real-path-enabled>true</show-archived-real-path-enabled>



الوقتى لما بجرب اشغل الصفحة بختار الصورة عادى لكن اول لما بضغط على الزر process اللى هو بينقل الصورة على السيرفر بيظهر الخطا دة

javax.faces.el.EvaluationException: java.lang.NullPointerException
<LifecycleImpl> <_handleException> ADF_FACES-60098:Faces lifecycle receives unhandled exceptions in phase INVOKE_APPLICATION 5
javax.faces.FacesException: #{backingBeanScope.basicInfo.processUpload}: java.lang.NullPointerException



لما جيت اعمل debug لاحظت ان بعد ما اعدى السطر دة
UploadedFile myfile = this.getFile();
الاقى ان المتغير myfile لسة قيمتة ب null

مش عارف لي بيجى ب null
يا ريت لو فى حد عندة مثال جاهز و مجربة يرفعة على المنتدى

شكرا

بتاريخ:

سلام
جربت نفس الطريفه و لم تنجح معي و عندما حددت المسار لم تنجح معي
getCurrentImageid()

بتاريخ:

ضع partialTriggers للزر بحيث يحتوي على id الـ inputFile

بتاريخ:

  String imageDirPath = servletCtx.getRealPath("/");
.
.
.

new File(imageDirPath + "/images/" + this.getCurrentEmployeeId()+".png");  


وضعت مجلد اسمه image في C:\JDeveloper\mywork\Application5\ViewController\public_html\images و لكني لا اجد الصور كيف و اين اعرف مجلد الصور

  • بعد 1 شهر...
بتاريخ:

Dear

as per my knowledge, using project internal directory to save employees images is a big false, as u will loose all images in 2nd deployment :)

so please use external directory and use a servlet to access otherwise use the BlobDomain solution to save in db blob column in Employee table

thanks

بتاريخ:
  • كاتب الموضوع

use external directory and use a servlet to access

thanks


Thank you for you recommendation . Do you have example about how to use servlet to access external directory?

تم تعديل بواسطة tarek_fathi

بتاريخ:

Dear Tarek



kindly use this one and please put these tages in your web.xml file (please note , i use/mnt/images as i have my stand aline wls in Linux platform)



<context-param>


<description>Directory of the image storage of the application</description>
<param-name>imageDirectory</param-name>
<param-value>/mnt/images</param-value>
</context-param>
<servlet>
<servlet-name>ImageServlet</servlet-name>
<servlet-class>Interface.backing.ImageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ImageServlet</servlet-name>
<url-pattern>/imagestorage/*</url-pattern>
</servlet-mapping>



--------------------------------------------------------------------



package Interface.backing;



import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import java.net.URLDecoder;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ImageServlet extends HttpServlet {
ServletConfig config;
// Constants --------------------------------------------------------------------------------
// 10KB.
private static final int DEFAULT_BUFFER_SIZE = 10240;

// Properties --------------------------------------------------------------------------------

private String imagePath;

// Actions --------------------------------------------------------------------------------

public void init(ServletConfig config) throws ServletException {
this.config = config;
ServletContext application = config.getServletContext();
this.imagePath = application.getInitParameter("imageDirectory");
super.init(config);
}

protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
String requestedImage = request.getPathInfo();

if (requestedImage == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}

File image =
new File(imagePath, URLDecoder.decode(requestedImage, "UTF-8"));

if (!image.exists()) {

response.sendError(HttpServletResponse.SC_NOT_FOUND); // 404.
return;
}

String contentType = getServletContext().getMimeType(image.getName());

if (contentType == null || !contentType.startsWith("image")) {
response.sendError(HttpServletResponse.SC_NOT_FOUND); // 404.
return;
}


response.reset();
response.setBufferSize(DEFAULT_BUFFER_SIZE);
response.setContentType(contentType);
response.setHeader("Content-Length", String.valueOf(image.length()));
response.setHeader("Content-Disposition",
"inline; filename=\"" + image.getName() + "\"");
BufferedInputStream input = null;
BufferedOutputStream output = null;

try {

input =
new BufferedInputStream(new FileInputStream(image), DEFAULT_BUFFER_SIZE);
output =
new BufferedOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE);

byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
int length;
while ((length = input.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
} finally {
close(output);
close(input);
}
}

private static void close(Closeable resource) {
if (resource != null) {
try {
resource.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

}


and Finally use this example to get get images based on its unique name based on its values saved in db



source="/imagestorage/#{bindings.ImageDirectory.inputValue}"



Good Luck

:)

تم تعديل بواسطة oracle_itself

بتاريخ:
  • كاتب الموضوع

Thank You so much for your help.
:)

انضم إلى المناقشة

يمكنك المشاركة الآن والتسجيل لاحقاً. إذا كان لديك حساب, سجل دخولك الآن لتقوم بالمشاركة من خلال حسابك.

زائر
أضف رد على هذا الموضوع...

برجاء الإنتباه

بإستخدامك للموقع فأنت تتعهد بالموافقة على هذه البنود: سياسة الخصوصية

Account

Navigation

البحث

إعداد إشعارات المتصفح الفورية

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.