admin管理员组文章数量:1026989
Hi all i was trying to upload a pdf file to my php server script i pdf file is there on android mobile it will be on sd card only so i want to open sd card of android device using phonegap via javascript.
Hi all i was trying to upload a pdf file to my php server script i pdf file is there on android mobile it will be on sd card only so i want to open sd card of android device using phonegap via javascript.
Share Improve this question asked Mar 30, 2012 at 9:50 user1051599user1051599 3712 gold badges7 silver badges18 bronze badges 1- See i did an image uploading for that i used navigator.camera.PictureSourceType.PHOTOLIBRARY fuction to open gallery like wise i need to open sdcard... how will i do... – user1051599 Commented Mar 30, 2012 at 10:02
2 Answers
Reset to default 5U can easily do that its very easy
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccessUpload, fail);
function onFileSystemSuccessUpload(fileSystem) {
// get directory entry through root and access all the folders
var directoryReader = fileSystem.root.createReader();
// Get a list of all the entries in the directory
directoryReader.readEntries(successReader,fail);
}
function successReader(entries) {
var i;
for (i=0; i<entries.length; i++) {
//alert(entries[i].name);
if(entries[i].isDirectory==true)
{
var directoryReaderIn = entries[i].createReader();
directoryReaderIn.readEntries(successReader,fail);
}
if(entries[i].isFile==true)
{
entries[i].file(uploadFile, fail);
}
}
};
function uploadFile(file) {
var target=""; //the url to upload on server
var ft = new FileTransfer(),path = "file://"+ file.fullPath,name = file.name;
ft.upload(path, target, win, fail, { fileName: name });
// var ft = new FileTransfer();
//ft.upload(file.fullPath, target, win, fail, options);
function win(r) {
alert("Code = " + r.responseCode);
alert("Response = " + r.response);
alert("Sent = " + r.bytesSent);
}
function fail(error) {
alert("An error has occurred: Code = " + error.code);
}
}
use this
navigator.camera.getPicture(successFn, errorFn, { quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
mediaType: navigator.camera.MediaType.ALLMEDIA });
this opens up options where u can choose files and selecting one will give u the name and path of the file in the successFn
Hi all i was trying to upload a pdf file to my php server script i pdf file is there on android mobile it will be on sd card only so i want to open sd card of android device using phonegap via javascript.
Hi all i was trying to upload a pdf file to my php server script i pdf file is there on android mobile it will be on sd card only so i want to open sd card of android device using phonegap via javascript.
Share Improve this question asked Mar 30, 2012 at 9:50 user1051599user1051599 3712 gold badges7 silver badges18 bronze badges 1- See i did an image uploading for that i used navigator.camera.PictureSourceType.PHOTOLIBRARY fuction to open gallery like wise i need to open sdcard... how will i do... – user1051599 Commented Mar 30, 2012 at 10:02
2 Answers
Reset to default 5U can easily do that its very easy
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccessUpload, fail);
function onFileSystemSuccessUpload(fileSystem) {
// get directory entry through root and access all the folders
var directoryReader = fileSystem.root.createReader();
// Get a list of all the entries in the directory
directoryReader.readEntries(successReader,fail);
}
function successReader(entries) {
var i;
for (i=0; i<entries.length; i++) {
//alert(entries[i].name);
if(entries[i].isDirectory==true)
{
var directoryReaderIn = entries[i].createReader();
directoryReaderIn.readEntries(successReader,fail);
}
if(entries[i].isFile==true)
{
entries[i].file(uploadFile, fail);
}
}
};
function uploadFile(file) {
var target=""; //the url to upload on server
var ft = new FileTransfer(),path = "file://"+ file.fullPath,name = file.name;
ft.upload(path, target, win, fail, { fileName: name });
// var ft = new FileTransfer();
//ft.upload(file.fullPath, target, win, fail, options);
function win(r) {
alert("Code = " + r.responseCode);
alert("Response = " + r.response);
alert("Sent = " + r.bytesSent);
}
function fail(error) {
alert("An error has occurred: Code = " + error.code);
}
}
use this
navigator.camera.getPicture(successFn, errorFn, { quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
mediaType: navigator.camera.MediaType.ALLMEDIA });
this opens up options where u can choose files and selecting one will give u the name and path of the file in the successFn
本文标签: javascriptHow to open SDCARD of android using phonegapStack Overflow
版权声明:本文标题:javascript - How to open SDCARD of android using phonegap - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745658093a2161717.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论