Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am using cordova FileTransfer plugin to upload and download in Android and IOS Mobile device,i am now stuck with receive in aspx page using HttpPostedFile

From mobile app i am transfer file using below code.
in button click event

JavaScript
function uploadFile() {


             navigator.camera.getPicture(
                 uploadPhoto,
                 function (message) {
                     $("#ErrorDiv").text("Failed to get a picture. Please select one.");
                 }, {
                     quality: 50,
                     destinationType: navigator.camera.DestinationType.FILE_URI,
                  sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
                               });



             function uploadPhoto(fileURI) {

                             var ft = new FileTransfer();
                             ft.upload(fileURI, encodeURI("http://" + localStorage.serverip + "/UService/ReceiveUpload.aspx"), UploadSuccess, UploadFail, options);


             }
         }


In above localStorage.serverip is server and in ReceiveUpload.aspx page load i write below code to retrive file and save in server machine folder.

VB
  Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        If Request.Files.Count <= 0 Then
            Exit Sub
        End If
        Dim MyFileCollection As HttpFileCollection

        MyFileCollection = Request.Files
        Dim postedFile As HttpPostedFile = Request.Files(0)
        Dim inStream As System.IO.Stream = postedFile.InputStream
        Dim fileData As Byte() = New Byte(postedFile.ContentLength - 1) {}
        inStream.Read(fileData, 0, postedFile.ContentLength)

        Dim writepath As String = Server.MapPath(".") & "\UserFiles"
        postedFile.SaveAs(writepath)
End Sub


If i am choose files from following ways ,it work fine
Gallery --> Camera or
Gallery--> Screenshots or
Gallery-->WhatsApp Images or
Gallert--> Pictures or from Dropbox

this is screenshot when i choose from above ways http://prntscr.com/dlkeh7 and it working.

But if choose files directly from Photos,Internal Storage,SD card cant transfer file using below code ,this is screenshot http://prntscr.com/dlkebn or http://prntscr.com/dlke7k

Request.Files count always get 0.

What wrong with fileURI ? in above screenshot i showed fileURI in alert msg.

What I have tried:

But if try to upload with following code can transfer from any location from mobile devices
JavaScript
document.addEventListener("deviceready", onDeviceReady, false);

          function onDeviceReady() {
               navigator.camera.getPicture(
               uploadPhoto,
               function(message) { alert('get picture failed'); },
               {
                   quality         : 50,
                   destinationType : navigator.camera.DestinationType.FILE_URI,
                   sourceType      : navigator.camera.PictureSourceType.PHOTOLIBRARY
               }
           );
       }

       function uploadPhoto(imageURI) {
           var options = new FileUploadOptions();
           options.fileKey="file";
           options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
           options.mimeType="image/jpeg";

           var params = {};
           params.value1 = "test";
           params.value2 = "param";

           options.params = params;

           var ft = new FileTransfer();
           ft.upload(imageURI, encodeURI("http://posttestserver.com/post.php"), win, fail, options);
       }



Pls reply asap

Regards
Aravind
Posted
Updated 23-Dec-16 1:47am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900