SlideShare a Scribd company logo
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)

More Related Content

What's hot

Servlet ppt by vikas jagtap
Servlet ppt by vikas jagtapServlet ppt by vikas jagtap
Servlet ppt by vikas jagtap
Vikas Jagtap
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server Page
Vipin Yadav
 
Jsp & Ajax
Jsp & AjaxJsp & Ajax
Jsp & Ajax
Ang Chen
 
Mule connector for ibm® as400
Mule connector for ibm® as400Mule connector for ibm® as400
Mule connector for ibm® as400
D.Rajesh Kumar
 
Mule jdbc
Mule   jdbcMule   jdbc
Mule jdbc
KalaimathiS
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1vikram singh
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
AnilKumar Etagowni
 
Jsp element
Jsp elementJsp element
Jsp element
kamal kotecha
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and Deployment
BG Java EE Course
 
Servlets
ServletsServlets
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
Fulvio Corno
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
BG Java EE Course
 
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 Works
Randy Connolly
 
Box connector Mule ESB Integration
Box connector Mule ESB IntegrationBox connector Mule ESB Integration
Box connector Mule ESB Integration
AnilKumar Etagowni
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
deepak kumar
 
Understanding JSP -Servlets
Understanding JSP -ServletsUnderstanding JSP -Servlets
Understanding JSP -Servlets
Gagandeep Singh
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsi krishna
 

What's hot (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
 

Viewers also liked

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
katie1head
 
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 final
muneeb777
 
Tango
TangoTango
Tango
mohd aijaj
 
Character profiles
Character profilesCharacter profiles
Character profiles
Oscar 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
 
Location research
Location researchLocation research
Location research
Ottilie Shpaizer
 
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 management
Yasir Karam
 
Project tango
Project tangoProject tango
Project tango
Sachin Gupta
 
Section A Revision: Ethnicity
Section A Revision: EthnicitySection A Revision: Ethnicity
Section A Revision: Ethnicity
CoombeMedia1
 
TEDxTaipei-Animal Protect
TEDxTaipei-Animal Protect TEDxTaipei-Animal Protect
TEDxTaipei-Animal Protect
Cheng wen cheng
 

Viewers also liked (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
 

Similar to 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
 
Php BASIC
Php BASICPhp 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 PlatformRobert Nyman
 
21 fbl integration-01
21   fbl integration-0121   fbl integration-01
21 fbl integration-01
mohamed 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 & Learnings
Johannes 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 APIs
James Pearce
 
Restap ito uploadfilessharepoint
Restap ito uploadfilessharepointRestap ito uploadfilessharepoint
Restap ito uploadfilessharepoint
MAHESH 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 devices
ciklum_ods
 
RESTAPI_SPHOSTED_APP
RESTAPI_SPHOSTED_APPRESTAPI_SPHOSTED_APP
RESTAPI_SPHOSTED_APP
MAHESH NEELANNAVAR
 
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 page
Glenn Jones
 
SocketStream
SocketStreamSocketStream
SocketStream
Paul Jensen
 

Similar to 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
 

More from 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 -apacoug20
Vinay 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 yatra20
Vinay Kumar
 
Extend soa with api management Sangam18
Extend soa with api management Sangam18Extend soa with api management Sangam18
Extend soa with api management Sangam18
Vinay Kumar
 
Extend soa with api management Doag18
Extend soa with api management Doag18Extend soa with api management Doag18
Extend soa with api management Doag18
Vinay Kumar
 
Roaring with elastic search sangam2018
Roaring with elastic search sangam2018Roaring with elastic search sangam2018
Roaring with elastic search sangam2018
Vinay 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- Madrid
Vinay 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 Madrid
Vinay 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 sangam17
Vinay 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-customzation
Vinay Kumar
 
Personalization in webcenter portal
Personalization in webcenter portalPersonalization in webcenter portal
Personalization in webcenter portal
Vinay Kumar
 
Custom audit rules in Jdeveloper extension
Custom audit rules in Jdeveloper extensionCustom audit rules in Jdeveloper extension
Custom audit rules in Jdeveloper extension
Vinay Kumar
 
Webcenter application performance tuning guide
Webcenter application performance tuning guideWebcenter application performance tuning guide
Webcenter application performance tuning guide
Vinay 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 paper
Vinay Kumar
 
Oracle adf performance tips
Oracle adf performance tipsOracle adf performance tips
Oracle adf performance tips
Vinay Kumar
 
JSR 168 Portal - Overview
JSR 168 Portal - OverviewJSR 168 Portal - Overview
JSR 168 Portal - Overview
Vinay Kumar
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
Vinay Kumar
 
Oracle Fusion Architecture
Oracle Fusion ArchitectureOracle Fusion Architecture
Oracle Fusion Architecture
Vinay Kumar
 
Incentive compensation in fusion CRM
Incentive compensation in fusion CRMIncentive compensation in fusion CRM
Incentive compensation in fusion CRM
Vinay Kumar
 

More from 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
 

Recently uploaded

Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 

Recently uploaded (20)

Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 

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)