SlideShare ist ein Scribd-Unternehmen logo
1 von 16
FILE UPLOAD IN
ORACLE ADF MOBILE
An Oracle White Paper – 12-03-2014
Vinay Kumar
Abstract
This paper demonstrates a way to upload a local file to a remote server in ADF
Mobile
Table of Contents
Setup:............................................................................................................................................................2
Steps Involved ..............................................................................................................................................2
Notes...........................................................................................................................................................15
Setup:
Install JDeveloper 11g Release 2 (version 11.1.2.3 or above) along with Oracle ADF Mobile
extension for JDeveloper. This can be done from Help  Check for Updates and then either
downloading the extension from Oracle or alternatively installing it from a local copy of the
Extension Zip file.
Install Android SDK. Create a virtual device if you would like to deploy on an emulator or else
you could also deploy directly to an actual Android device. Configure the ADF Mobile
environment for Android from Tools ->Preferences->ADF Mobile-> Platforms.
Steps Involved
We will consider a simple business use case where the user is required to click a photograph with
the device camera and upload it to a remote server.
Creating the application and task flow:
Open JDeveloper. Create a new application and select the type as Mobile Application (ADF)
Click “OK”, name your application (for this example we will name it as “FileTransferDemo”),
and then click “Next” on all subsequent dialog windows, accepting all default options, and
finally click on “Finish”.
Create a new feature in the adfmf-feature.xml. Name it as “FileTransfer”. Create a new AMX
page under the Contents tab and name it “upload.amx”.
Create a new JavaScript file, name it “myjs.js”.
Include the myjs.js file in the current feature as shown below:
Now edit the JavaScript file as follows:
(function () {
if (!window.application)
window.application = {
};
snapUpload = function () {
// take picture
navigator.camera.getPicture(uploadPhoto, function (message) {
alert("get picture failed");
},
{
quality : 50, destinationType :
navigator.camera.DestinationType.FILE_URI,
sourceType : navigator.camera.PictureSourceType.CAMERA
});
};
function uploadPhoto(imageURI) {
var options = new FileUploadOptions();
options.fileKey = "file";
// extract filename from URI
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
var params = {
};
options.params = params;
var ft = new FileTransfer();
// upload to server
ft.upload(imageURI, encodeURI("http://10.87.194.23:7101/FileUpload-
ViewController-
context-root/upload.jsp"), success, fail, options);
}
function success(response) {
alert("File uploaded successfully");
// log response
console.log("Code = " + response.responseCode);
console.log("Response = " + response.response);
console.log("Sent = " + response.bytesSent);
}
function fail(error) {
alert("An error has occurred: Code = " + error.code);
// log error
console.log("Upload error source " + error.source);
console.log("Upload error target " + error.target);
}
})();
Now we will add code in the AMX page that will call the JavaScript functions. First create a
bean with a method that will call the JavaScript function snapUpload, and register it as a
managed bean in the adf-mobile-config.xml file as shown:
package mobile;
import oracle.adfmf.amx.event.ActionEvent;
import oracle.adfmf.framework.api.AdfmfContainerUtilities;
public class MyBean {
public void snapUpload(ActionEvent ae) { // action listener method
// call JavaScript function to take picture and upload to server
AdfmfContainerUtilities.invokeContainerJavaScriptFunction("FileTransfe
r",
"snapUpload", new Object [] {});
}
}
Edit the upload.amx page as follows:
<?xml version="1.0" encoding="UTF-8" ?>
<amx:view xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:amx="http://xmlns.oracle.com/adf/mf/amx"
xmlns:dvtm="http://xmlns.oracle.com/adf/mf/amx/dvt">
<amx:panelPage id="pp1">
<amx:facet name="header">
<amx:outputText value="Image Upload" id="ot1"/>
</amx:facet>
<amx:commandButton text="Upload Photo" id="cb1"
actionListener="#{pageFlowScope.myBean.snapUpload}"/>
</amx:panelPage>
</amx:view>
Basically, we are associating an action listener with a button that calls the JavaScript function
from our Java code.
The server must be up and running for the file upload to work. The URL provided must point to
a page that accepts a file whose contents are sent in the body of a POST request. In our case, we
are using a JSP page, but any other web technology may be used like PHP, ASP.NET etc.
The following code lists our simple upload.jsp page:
<%@ page language="java" import="java.io.*" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4
<%
// get the content type information from JSP Request Header
String contentType = request.getContentType();
// content type should not be null and data passed from mulitpart/form-data is greater tha
to 0
if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
DataInputStream in = new DataInputStream(request.getInputStream());
// get length of the data content
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
// read bytes while available
while (totalBytesRead < formDataLength) {
byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
totalBytesRead += byteRead;
}
String file = new String(dataBytes);
// get filename for saving
String saveFile = file.substring(file.indexOf("filename="") + 10);
saveFile = saveFile.substring(0, saveFile.indexOf("n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("") + 1,saveFile.indexOf("""));
int lastIndex = contentType.lastIndexOf("=");
// get boundary delimiter from header
String boundary = contentType.substring(lastIndex + 1, contentType.length());
int pos;
// locate start and end positions of file data within request
pos = file.indexOf("filename="");
pos = file.indexOf("n", pos) + 1;
pos = file.indexOf("n", pos) + 1;
pos = file.indexOf("n", pos) + 1;
int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
// create a new file with the same name as source and copy the file contents to it
FileOutputStream fout = new FileOutputStream(saveFile);
fout.write(dataBytes, startPos, (endPos - startPos));
fout.flush();
fout.close();
%>
<br></br>
<table border="2">
<tr>
<td>
<b>You have successfully uploaded the file by the name of:</b>
<%=new File(saveFile).getAbsolutePath()%>
</td>
</tr>
</table>
<%
} // end if
%>
Finally, deploy the application to an Android device or emulator using the Application  Deploy
menu.Tapping on the “Upload Photo” button opens up the device camera using which you can
snap a picture.
After you have clicked the photo the file is uploaded to the server. Upon successful upload the
user is alerted accordingly.
Looking at the log file “FileTransferDemo.txt” under the sdcard root you can see the response
code, the HTML response from the server and the number of bytes transferred has been logged.
You can view the log file by typing “file:///sdcard/FileTransferDemo.txt” in the address bar of
the device browser.
Notes
Using PhoneGap/Apache Cordova it is possible to upload any kind of file by simply changing
the URI and the MIME type. For a better user experience we could integrate a file browser to
locate and select our desired file from the device’s local file system. For a demonstration on
using a filesystem browser in ADF
At the server side we have used a very simple implementation of an upload page. However,
depending on requirements this upload page might need to be able to read one or more
parameters and involve other complexities. Typically, if we are leveraging Apache and JEE
technology to host our server it is often a popular choice to use Apache HttpClient or
HttpComponents libraries.
References
1. Oracle Fusion Middleware Mobile Developer’s Guide for Oracle Application Development
Framework (http://docs.oracle.com/cd/E35521_01/doc.111230/e24475/toc.htm)
2. PhoneGap API Documentation (http://docs.phonegap.com/en/1.0.0/index.html)
3. Uploading Single File by Using JSP
(http://www.roseindia.net/jsp/file_upload/Sinle_upload.xhtml.shtml)

Weitere Àhnliche Inhalte

Was ist angesagt?

Servlet ppt by vikas jagtap
Servlet ppt by vikas jagtapServlet ppt by vikas jagtap
Servlet ppt by vikas jagtapVikas Jagtap
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server PageVipin Yadav
 
Jsp & Ajax
Jsp & AjaxJsp & Ajax
Jsp & AjaxAng Chen
 
Mule connector for ibmÂź as400
Mule connector for ibmÂź as400Mule connector for ibmÂź as400
Mule connector for ibmÂź as400D.Rajesh Kumar
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1vikram singh
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and DeploymentBG Java EE Course
 
Web services in PHP using the NuSOAP library
Web services in PHP using the NuSOAP libraryWeb services in PHP using the NuSOAP library
Web services in PHP using the NuSOAP libraryFulvio Corno
 
Java Servlet
Java Servlet Java Servlet
Java Servlet Rajiv Gupta
 
Web II - 02 - How ASP.NET Works
Web II - 02 - How ASP.NET WorksWeb II - 02 - How ASP.NET Works
Web II - 02 - How ASP.NET WorksRandy Connolly
 
Box connector Mule ESB Integration
Box connector Mule ESB IntegrationBox connector Mule ESB Integration
Box connector Mule ESB IntegrationAnilKumar Etagowni
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servletsdeepak kumar
 
Understanding JSP -Servlets
Understanding JSP -ServletsUnderstanding JSP -Servlets
Understanding JSP -ServletsGagandeep Singh
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsi krishna
 

Was ist angesagt? (20)

Servlet ppt by vikas jagtap
Servlet ppt by vikas jagtapServlet ppt by vikas jagtap
Servlet ppt by vikas jagtap
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server Page
 
Jsp & Ajax
Jsp & AjaxJsp & Ajax
Jsp & Ajax
 
Mule connector for ibmÂź as400
Mule connector for ibmÂź as400Mule connector for ibmÂź as400
Mule connector for ibmÂź as400
 
Mule jdbc
Mule   jdbcMule   jdbc
Mule jdbc
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
 
Jsp element
Jsp elementJsp element
Jsp element
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and Deployment
 
Servlets
ServletsServlets
Servlets
 
Servlets
ServletsServlets
Servlets
 
Web services in PHP using the NuSOAP library
Web services in PHP using the NuSOAP libraryWeb services in PHP using the NuSOAP library
Web services in PHP using the NuSOAP library
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Java Servlet
Java Servlet Java Servlet
Java Servlet
 
Web II - 02 - How ASP.NET Works
Web II - 02 - How ASP.NET WorksWeb II - 02 - How ASP.NET Works
Web II - 02 - How ASP.NET Works
 
Box connector Mule ESB Integration
Box connector Mule ESB IntegrationBox connector Mule ESB Integration
Box connector Mule ESB Integration
 
Lect06 tomcat1
Lect06 tomcat1Lect06 tomcat1
Lect06 tomcat1
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
 
Understanding JSP -Servlets
Understanding JSP -ServletsUnderstanding JSP -Servlets
Understanding JSP -Servlets
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 

Andere mochten auch

History of film and Neo Noir timeline
History of film and Neo Noir timelineHistory of film and Neo Noir timeline
History of film and Neo Noir timelinekatie1head
 
SLALOM Project Technical Webinar 20151111
SLALOM Project Technical Webinar 20151111 SLALOM Project Technical Webinar 20151111
SLALOM Project Technical Webinar 20151111 Oliver Barreto RodrĂ­guez
 
award-3b07c32b-b116-3a75-8974-d814d37026ca
award-3b07c32b-b116-3a75-8974-d814d37026caaward-3b07c32b-b116-3a75-8974-d814d37026ca
award-3b07c32b-b116-3a75-8974-d814d37026caVinay Kumar
 
Samba bank ppt final
Samba bank ppt finalSamba bank ppt final
Samba bank ppt finalmuneeb777
 
Character profiles
Character profilesCharacter profiles
Character profilesOscar Wright
 
Fibre Optics Seminar Ise09
Fibre Optics Seminar Ise09Fibre Optics Seminar Ise09
Fibre Optics Seminar Ise09franksheehan
 
Call Sheets for "Street Style"
Call Sheets for "Street Style"Call Sheets for "Street Style"
Call Sheets for "Street Style"Erika Andrejuskinaite
 
Google I/O 2016: What to expect from Android N to virtual reality?
Google I/O 2016: What to expect from Android N to virtual reality?Google I/O 2016: What to expect from Android N to virtual reality?
Google I/O 2016: What to expect from Android N to virtual reality?ChromeInfo Technologies
 
Service level management
Service level managementService level management
Service level managementYasir Karam
 
Project tango
Project tangoProject tango
Project tangoSachin Gupta
 
Section A Revision: Ethnicity
Section A Revision: EthnicitySection A Revision: Ethnicity
Section A Revision: EthnicityCoombeMedia1
 
TEDxTaipei-Animal Protect
TEDxTaipei-Animal Protect TEDxTaipei-Animal Protect
TEDxTaipei-Animal Protect Cheng wen cheng
 

Andere mochten auch (16)

History of film and Neo Noir timeline
History of film and Neo Noir timelineHistory of film and Neo Noir timeline
History of film and Neo Noir timeline
 
SLALOM Project Technical Webinar 20151111
SLALOM Project Technical Webinar 20151111 SLALOM Project Technical Webinar 20151111
SLALOM Project Technical Webinar 20151111
 
award-3b07c32b-b116-3a75-8974-d814d37026ca
award-3b07c32b-b116-3a75-8974-d814d37026caaward-3b07c32b-b116-3a75-8974-d814d37026ca
award-3b07c32b-b116-3a75-8974-d814d37026ca
 
Amitava_resume
Amitava_resumeAmitava_resume
Amitava_resume
 
Samba bank ppt final
Samba bank ppt finalSamba bank ppt final
Samba bank ppt final
 
Spanish dances tango
Spanish dances tangoSpanish dances tango
Spanish dances tango
 
Tango
TangoTango
Tango
 
Character profiles
Character profilesCharacter profiles
Character profiles
 
Fibre Optics Seminar Ise09
Fibre Optics Seminar Ise09Fibre Optics Seminar Ise09
Fibre Optics Seminar Ise09
 
Call Sheets for "Street Style"
Call Sheets for "Street Style"Call Sheets for "Street Style"
Call Sheets for "Street Style"
 
Location research
Location researchLocation research
Location research
 
Google I/O 2016: What to expect from Android N to virtual reality?
Google I/O 2016: What to expect from Android N to virtual reality?Google I/O 2016: What to expect from Android N to virtual reality?
Google I/O 2016: What to expect from Android N to virtual reality?
 
Service level management
Service level managementService level management
Service level management
 
Project tango
Project tangoProject tango
Project tango
 
Section A Revision: Ethnicity
Section A Revision: EthnicitySection A Revision: Ethnicity
Section A Revision: Ethnicity
 
TEDxTaipei-Animal Protect
TEDxTaipei-Animal Protect TEDxTaipei-Animal Protect
TEDxTaipei-Animal Protect
 

Ähnlich wie File upload in oracle adf mobile

Cliw - extension development
Cliw -  extension developmentCliw -  extension development
Cliw - extension developmentvicccuu
 
Php File Upload
Php File UploadPhp File Upload
Php File Uploadsaeel005
 
JavaScript APIs - The Web is the Platform
JavaScript APIs - The Web is the PlatformJavaScript APIs - The Web is the Platform
JavaScript APIs - The Web is the PlatformRobert Nyman
 
21 fbl integration-01
21   fbl integration-0121   fbl integration-01
21 fbl integration-01mohamed refaei
 
HTML5 APIs - Where No Man Has Gone Before! - GothamJS
HTML5 APIs - Where No Man Has Gone Before! - GothamJSHTML5 APIs - Where No Man Has Gone Before! - GothamJS
HTML5 APIs - Where No Man Has Gone Before! - GothamJSRobert Nyman
 
BlackBerry DevCon 2011 - PhoneGap and WebWorks
BlackBerry DevCon 2011 - PhoneGap and WebWorksBlackBerry DevCon 2011 - PhoneGap and WebWorks
BlackBerry DevCon 2011 - PhoneGap and WebWorksmwbrooks
 
The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it meansRobert Nyman
 
Progressive Web Apps - Intro & Learnings
Progressive Web Apps - Intro & LearningsProgressive Web Apps - Intro & Learnings
Progressive Web Apps - Intro & LearningsJohannes Weber
 
HTML5 APIs - Where No Man Has Gone Before! - Paris Web
HTML5 APIs -  Where No Man Has Gone Before! - Paris WebHTML5 APIs -  Where No Man Has Gone Before! - Paris Web
HTML5 APIs - Where No Man Has Gone Before! - Paris WebRobert Nyman
 
If love is_blind_-_tiffany
If love is_blind_-_tiffanyIf love is_blind_-_tiffany
If love is_blind_-_tiffanytenka
 
Mobile Device APIs
Mobile Device APIsMobile Device APIs
Mobile Device APIsJames Pearce
 
Restap ito uploadfilessharepoint
Restap ito uploadfilessharepointRestap ito uploadfilessharepoint
Restap ito uploadfilessharepointMAHESH NEELANNAVAR
 
Rapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devicesRapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devicesciklum_ods
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...SPTechCon
 
Beyond the page
Beyond the pageBeyond the page
Beyond the pageGlenn Jones
 
SocketStream
SocketStreamSocketStream
SocketStreamPaul Jensen
 

Ähnlich wie File upload in oracle adf mobile (20)

Cliw - extension development
Cliw -  extension developmentCliw -  extension development
Cliw - extension development
 
Php File Upload
Php File UploadPhp File Upload
Php File Upload
 
Php BASIC
Php BASICPhp BASIC
Php BASIC
 
JavaScript APIs - The Web is the Platform
JavaScript APIs - The Web is the PlatformJavaScript APIs - The Web is the Platform
JavaScript APIs - The Web is the Platform
 
21 fbl integration-01
21   fbl integration-0121   fbl integration-01
21 fbl integration-01
 
HTML5 APIs - Where No Man Has Gone Before! - GothamJS
HTML5 APIs - Where No Man Has Gone Before! - GothamJSHTML5 APIs - Where No Man Has Gone Before! - GothamJS
HTML5 APIs - Where No Man Has Gone Before! - GothamJS
 
BlackBerry DevCon 2011 - PhoneGap and WebWorks
BlackBerry DevCon 2011 - PhoneGap and WebWorksBlackBerry DevCon 2011 - PhoneGap and WebWorks
BlackBerry DevCon 2011 - PhoneGap and WebWorks
 
Servlets
ServletsServlets
Servlets
 
The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it means
 
Progressive Web Apps - Intro & Learnings
Progressive Web Apps - Intro & LearningsProgressive Web Apps - Intro & Learnings
Progressive Web Apps - Intro & Learnings
 
HTML5 APIs - Where No Man Has Gone Before! - Paris Web
HTML5 APIs -  Where No Man Has Gone Before! - Paris WebHTML5 APIs -  Where No Man Has Gone Before! - Paris Web
HTML5 APIs - Where No Man Has Gone Before! - Paris Web
 
If love is_blind_-_tiffany
If love is_blind_-_tiffanyIf love is_blind_-_tiffany
If love is_blind_-_tiffany
 
Mobile Device APIs
Mobile Device APIsMobile Device APIs
Mobile Device APIs
 
Restap ito uploadfilessharepoint
Restap ito uploadfilessharepointRestap ito uploadfilessharepoint
Restap ito uploadfilessharepoint
 
Rapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devicesRapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devices
 
RESTAPI_SPHOSTED_APP
RESTAPI_SPHOSTED_APPRESTAPI_SPHOSTED_APP
RESTAPI_SPHOSTED_APP
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
 
Beyond the page
Beyond the pageBeyond the page
Beyond the page
 
Pushing the Web: Interesting things to Know
Pushing the Web: Interesting things to KnowPushing the Web: Interesting things to Know
Pushing the Web: Interesting things to Know
 
SocketStream
SocketStreamSocketStream
SocketStream
 

Mehr von Vinay Kumar

Modernizing the monolithic architecture to container based architecture apaco...
Modernizing the monolithic architecture to container based architecture apaco...Modernizing the monolithic architecture to container based architecture apaco...
Modernizing the monolithic architecture to container based architecture apaco...Vinay Kumar
 
Kafka and event driven architecture -apacoug20
Kafka and event driven architecture -apacoug20Kafka and event driven architecture -apacoug20
Kafka and event driven architecture -apacoug20Vinay Kumar
 
Kafka and event driven architecture -og yatra20
Kafka and event driven architecture -og yatra20Kafka and event driven architecture -og yatra20
Kafka and event driven architecture -og yatra20Vinay Kumar
 
Extend soa with api management Sangam18
Extend soa with api management Sangam18Extend soa with api management Sangam18
Extend soa with api management Sangam18Vinay Kumar
 
Extend soa with api management Doag18
Extend soa with api management Doag18Extend soa with api management Doag18
Extend soa with api management Doag18Vinay Kumar
 
Roaring with elastic search sangam2018
Roaring with elastic search sangam2018Roaring with elastic search sangam2018
Roaring with elastic search sangam2018Vinay Kumar
 
Extend soa with api management spoug- Madrid
Extend soa with api management   spoug- MadridExtend soa with api management   spoug- Madrid
Extend soa with api management spoug- MadridVinay Kumar
 
Expose your data as an api is with oracle rest data services -spoug Madrid
Expose your data as an api is with oracle rest data services -spoug MadridExpose your data as an api is with oracle rest data services -spoug Madrid
Expose your data as an api is with oracle rest data services -spoug MadridVinay Kumar
 
Modern application development with oracle cloud sangam17
Modern application development with oracle cloud sangam17Modern application development with oracle cloud sangam17
Modern application development with oracle cloud sangam17Vinay Kumar
 
award-3b07c32b-b116-3a75-8974-d814d37026ca
award-3b07c32b-b116-3a75-8974-d814d37026caaward-3b07c32b-b116-3a75-8974-d814d37026ca
award-3b07c32b-b116-3a75-8974-d814d37026caVinay Kumar
 
Adf spotlight-webcenter task flow-customzation
Adf spotlight-webcenter task flow-customzationAdf spotlight-webcenter task flow-customzation
Adf spotlight-webcenter task flow-customzationVinay Kumar
 
Personalization in webcenter portal
Personalization in webcenter portalPersonalization in webcenter portal
Personalization in webcenter portalVinay Kumar
 
Custom audit rules in Jdeveloper extension
Custom audit rules in Jdeveloper extensionCustom audit rules in Jdeveloper extension
Custom audit rules in Jdeveloper extensionVinay Kumar
 
Webcenter application performance tuning guide
Webcenter application performance tuning guideWebcenter application performance tuning guide
Webcenter application performance tuning guideVinay Kumar
 
Tuning and optimizing webcenter spaces application white paper
Tuning and optimizing webcenter spaces application white paperTuning and optimizing webcenter spaces application white paper
Tuning and optimizing webcenter spaces application white paperVinay Kumar
 
Oracle adf performance tips
Oracle adf performance tipsOracle adf performance tips
Oracle adf performance tipsVinay Kumar
 
JSR 168 Portal - Overview
JSR 168 Portal - OverviewJSR 168 Portal - Overview
JSR 168 Portal - OverviewVinay Kumar
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depthVinay Kumar
 
Oracle Fusion Architecture
Oracle Fusion ArchitectureOracle Fusion Architecture
Oracle Fusion ArchitectureVinay Kumar
 
Incentive compensation in fusion CRM
Incentive compensation in fusion CRMIncentive compensation in fusion CRM
Incentive compensation in fusion CRMVinay Kumar
 

Mehr von Vinay Kumar (20)

Modernizing the monolithic architecture to container based architecture apaco...
Modernizing the monolithic architecture to container based architecture apaco...Modernizing the monolithic architecture to container based architecture apaco...
Modernizing the monolithic architecture to container based architecture apaco...
 
Kafka and event driven architecture -apacoug20
Kafka and event driven architecture -apacoug20Kafka and event driven architecture -apacoug20
Kafka and event driven architecture -apacoug20
 
Kafka and event driven architecture -og yatra20
Kafka and event driven architecture -og yatra20Kafka and event driven architecture -og yatra20
Kafka and event driven architecture -og yatra20
 
Extend soa with api management Sangam18
Extend soa with api management Sangam18Extend soa with api management Sangam18
Extend soa with api management Sangam18
 
Extend soa with api management Doag18
Extend soa with api management Doag18Extend soa with api management Doag18
Extend soa with api management Doag18
 
Roaring with elastic search sangam2018
Roaring with elastic search sangam2018Roaring with elastic search sangam2018
Roaring with elastic search sangam2018
 
Extend soa with api management spoug- Madrid
Extend soa with api management   spoug- MadridExtend soa with api management   spoug- Madrid
Extend soa with api management spoug- Madrid
 
Expose your data as an api is with oracle rest data services -spoug Madrid
Expose your data as an api is with oracle rest data services -spoug MadridExpose your data as an api is with oracle rest data services -spoug Madrid
Expose your data as an api is with oracle rest data services -spoug Madrid
 
Modern application development with oracle cloud sangam17
Modern application development with oracle cloud sangam17Modern application development with oracle cloud sangam17
Modern application development with oracle cloud sangam17
 
award-3b07c32b-b116-3a75-8974-d814d37026ca
award-3b07c32b-b116-3a75-8974-d814d37026caaward-3b07c32b-b116-3a75-8974-d814d37026ca
award-3b07c32b-b116-3a75-8974-d814d37026ca
 
Adf spotlight-webcenter task flow-customzation
Adf spotlight-webcenter task flow-customzationAdf spotlight-webcenter task flow-customzation
Adf spotlight-webcenter task flow-customzation
 
Personalization in webcenter portal
Personalization in webcenter portalPersonalization in webcenter portal
Personalization in webcenter portal
 
Custom audit rules in Jdeveloper extension
Custom audit rules in Jdeveloper extensionCustom audit rules in Jdeveloper extension
Custom audit rules in Jdeveloper extension
 
Webcenter application performance tuning guide
Webcenter application performance tuning guideWebcenter application performance tuning guide
Webcenter application performance tuning guide
 
Tuning and optimizing webcenter spaces application white paper
Tuning and optimizing webcenter spaces application white paperTuning and optimizing webcenter spaces application white paper
Tuning and optimizing webcenter spaces application white paper
 
Oracle adf performance tips
Oracle adf performance tipsOracle adf performance tips
Oracle adf performance tips
 
JSR 168 Portal - Overview
JSR 168 Portal - OverviewJSR 168 Portal - Overview
JSR 168 Portal - Overview
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
 
Oracle Fusion Architecture
Oracle Fusion ArchitectureOracle Fusion Architecture
Oracle Fusion Architecture
 
Incentive compensation in fusion CRM
Incentive compensation in fusion CRMIncentive compensation in fusion CRM
Incentive compensation in fusion CRM
 

KĂŒrzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 

KĂŒrzlich hochgeladen (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 

File upload in oracle adf mobile

  • 1. FILE UPLOAD IN ORACLE ADF MOBILE An Oracle White Paper – 12-03-2014 Vinay Kumar Abstract This paper demonstrates a way to upload a local file to a remote server in ADF Mobile
  • 2. Table of Contents Setup:............................................................................................................................................................2 Steps Involved ..............................................................................................................................................2 Notes...........................................................................................................................................................15
  • 3. Setup: Install JDeveloper 11g Release 2 (version 11.1.2.3 or above) along with Oracle ADF Mobile extension for JDeveloper. This can be done from Help  Check for Updates and then either downloading the extension from Oracle or alternatively installing it from a local copy of the Extension Zip file. Install Android SDK. Create a virtual device if you would like to deploy on an emulator or else you could also deploy directly to an actual Android device. Configure the ADF Mobile environment for Android from Tools ->Preferences->ADF Mobile-> Platforms. Steps Involved We will consider a simple business use case where the user is required to click a photograph with the device camera and upload it to a remote server. Creating the application and task flow: Open JDeveloper. Create a new application and select the type as Mobile Application (ADF)
  • 4. Click “OK”, name your application (for this example we will name it as “FileTransferDemo”), and then click “Next” on all subsequent dialog windows, accepting all default options, and finally click on “Finish”.
  • 5. Create a new feature in the adfmf-feature.xml. Name it as “FileTransfer”. Create a new AMX page under the Contents tab and name it “upload.amx”.
  • 6. Create a new JavaScript file, name it “myjs.js”.
  • 7. Include the myjs.js file in the current feature as shown below:
  • 8. Now edit the JavaScript file as follows: (function () { if (!window.application) window.application = { }; snapUpload = function () { // take picture navigator.camera.getPicture(uploadPhoto, function (message) { alert("get picture failed"); }, { quality : 50, destinationType : navigator.camera.DestinationType.FILE_URI, sourceType : navigator.camera.PictureSourceType.CAMERA }); };
  • 9. function uploadPhoto(imageURI) { var options = new FileUploadOptions(); options.fileKey = "file"; // extract filename from URI options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1); options.mimeType = "image/jpeg"; var params = { }; options.params = params; var ft = new FileTransfer(); // upload to server ft.upload(imageURI, encodeURI("http://10.87.194.23:7101/FileUpload- ViewController- context-root/upload.jsp"), success, fail, options); } function success(response) { alert("File uploaded successfully"); // log response console.log("Code = " + response.responseCode); console.log("Response = " + response.response); console.log("Sent = " + response.bytesSent); } function fail(error) { alert("An error has occurred: Code = " + error.code); // log error console.log("Upload error source " + error.source); console.log("Upload error target " + error.target); } })(); Now we will add code in the AMX page that will call the JavaScript functions. First create a bean with a method that will call the JavaScript function snapUpload, and register it as a managed bean in the adf-mobile-config.xml file as shown:
  • 10. package mobile; import oracle.adfmf.amx.event.ActionEvent; import oracle.adfmf.framework.api.AdfmfContainerUtilities; public class MyBean { public void snapUpload(ActionEvent ae) { // action listener method // call JavaScript function to take picture and upload to server AdfmfContainerUtilities.invokeContainerJavaScriptFunction("FileTransfe r", "snapUpload", new Object [] {}); } } Edit the upload.amx page as follows:
  • 11. <?xml version="1.0" encoding="UTF-8" ?> <amx:view xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:amx="http://xmlns.oracle.com/adf/mf/amx" xmlns:dvtm="http://xmlns.oracle.com/adf/mf/amx/dvt"> <amx:panelPage id="pp1"> <amx:facet name="header"> <amx:outputText value="Image Upload" id="ot1"/> </amx:facet> <amx:commandButton text="Upload Photo" id="cb1" actionListener="#{pageFlowScope.myBean.snapUpload}"/> </amx:panelPage> </amx:view> Basically, we are associating an action listener with a button that calls the JavaScript function from our Java code. The server must be up and running for the file upload to work. The URL provided must point to a page that accepts a file whose contents are sent in the body of a POST request. In our case, we are using a JSP page, but any other web technology may be used like PHP, ASP.NET etc. The following code lists our simple upload.jsp page: <%@ page language="java" import="java.io.*" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4 <% // get the content type information from JSP Request Header String contentType = request.getContentType(); // content type should not be null and data passed from mulitpart/form-data is greater tha to 0 if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) { DataInputStream in = new DataInputStream(request.getInputStream()); // get length of the data content int formDataLength = request.getContentLength(); byte dataBytes[] = new byte[formDataLength]; int byteRead = 0; int totalBytesRead = 0; // read bytes while available while (totalBytesRead < formDataLength) { byteRead = in.read(dataBytes, totalBytesRead, formDataLength); totalBytesRead += byteRead; } String file = new String(dataBytes); // get filename for saving String saveFile = file.substring(file.indexOf("filename="") + 10); saveFile = saveFile.substring(0, saveFile.indexOf("n")); saveFile = saveFile.substring(saveFile.lastIndexOf("") + 1,saveFile.indexOf(""")); int lastIndex = contentType.lastIndexOf("="); // get boundary delimiter from header String boundary = contentType.substring(lastIndex + 1, contentType.length()); int pos; // locate start and end positions of file data within request pos = file.indexOf("filename=""); pos = file.indexOf("n", pos) + 1; pos = file.indexOf("n", pos) + 1; pos = file.indexOf("n", pos) + 1; int boundaryLocation = file.indexOf(boundary, pos) - 4;
  • 12. int startPos = ((file.substring(0, pos)).getBytes()).length; int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length; // create a new file with the same name as source and copy the file contents to it FileOutputStream fout = new FileOutputStream(saveFile); fout.write(dataBytes, startPos, (endPos - startPos)); fout.flush(); fout.close(); %> <br></br> <table border="2"> <tr> <td> <b>You have successfully uploaded the file by the name of:</b> <%=new File(saveFile).getAbsolutePath()%> </td> </tr> </table> <% } // end if %> Finally, deploy the application to an Android device or emulator using the Application  Deploy menu.Tapping on the “Upload Photo” button opens up the device camera using which you can
  • 14. After you have clicked the photo the file is uploaded to the server. Upon successful upload the user is alerted accordingly.
  • 15. Looking at the log file “FileTransferDemo.txt” under the sdcard root you can see the response code, the HTML response from the server and the number of bytes transferred has been logged. You can view the log file by typing “file:///sdcard/FileTransferDemo.txt” in the address bar of the device browser.
  • 16. Notes Using PhoneGap/Apache Cordova it is possible to upload any kind of file by simply changing the URI and the MIME type. For a better user experience we could integrate a file browser to locate and select our desired file from the device’s local file system. For a demonstration on using a filesystem browser in ADF At the server side we have used a very simple implementation of an upload page. However, depending on requirements this upload page might need to be able to read one or more parameters and involve other complexities. Typically, if we are leveraging Apache and JEE technology to host our server it is often a popular choice to use Apache HttpClient or HttpComponents libraries. References 1. Oracle Fusion Middleware Mobile Developer’s Guide for Oracle Application Development Framework (http://docs.oracle.com/cd/E35521_01/doc.111230/e24475/toc.htm) 2. PhoneGap API Documentation (http://docs.phonegap.com/en/1.0.0/index.html) 3. Uploading Single File by Using JSP (http://www.roseindia.net/jsp/file_upload/Sinle_upload.xhtml.shtml)