fileupload error file not found

5 posts, 4 answers
  1. Answer
    Roger avatar
    183 posts
    Member since:
    Sep 2007

    Posted 13 Jan 2014 Link to this post

    am trying to upload a file from an android device (not the emulator).
    I'm using the uri of 
    var fileURI = fileSys.root.fullPath + '/lightning/attachments/theFile.pdf'
    to get

    file:///storage/sdcard0/lightning/attachments/theFile.pdf (which exists...I checked).

    so if I do 
    I get an error code of 1 (File not Found)
    I even did a resolveLocalFileSystemURI to get a fileEntry object and use entry.fullPath in the upload function with the same result, but at least I know that the file can be accessed.
    Is there some permissions problem or what the heck is going on ????

  2. Answer
    Roger avatar
    183 posts
    Member since:
    Sep 2007

    Posted 13 Jan 2014 Link to this post

    done some more investigation and found that the filetransfer.upload is not accessing my WCF rest service....not even the catch all something wrong here.
    The file not found was referring to the website not being found.
    Can use Chrome Poster to post a request to the service and it is accepted OK and logs that access has been made. Can also post the file to an aspx page and it is sent OK.
    The service is run from a hosted web site so can't put any 3rd party tools on there.
    Have scoured the WCF website and can't find any solution....
    code is:
            <WebInvoke(UriTemplate:="attachmentSave", Method:="POST", requestFormat:=WebMessageFormat.Json, responseFormat:=WebMessageFormat.Json, bodystyle:=WebMessageBodyStyle.WrappedRequest)>
            Public Function Attachment_Save() As Stream
    End Function

    have tried putting 
    Public Function Attachment_Save(data as stream) As Stream
    as some sites have suggested.

    Is it a multi=part problem?

  3. Answer
    Roger avatar
    183 posts
    Member since:
    Sep 2007

    Posted 14 Jan 2014 Link to this post


    Done some more research:

    WCF REST will not accept a post from Cordova 3.2.0 FileTransfer.upload.

    Created an asmx web service and this accepts the post and downloads the file with filename, content type, etc, but cannot get parameters. All the posts about getting them from HttpContext.Current.Request.Params don't work.

    Of course, POST does not accept querystrings so cannot send any identifying info with the file.


    you can add headers to the FileTransfer.upload. config

    var options  = new FileUploadOptions();

    options.fileKey = "data";

    options.fileName = fileURI.substr(fileURI.lastIndexOf('/') + 1);

    options.mimeType = "image/jpeg";

    options.chunkedMode = false;

    options.headers = {Connection: "close", Data:["Test","param"]}

    so when you look at params.GetValues("HTTP_DATA")(0)

    where params = HttpContext.Current.Request.Params

    you'll get a result of  "test,params" which you can do a split on the "," on to separate.

    Either that or add individual headers.

    Might not be the most elegant method but it works & you'll get the data as well as the file.


  4. Answer
    Roger avatar
    183 posts
    Member since:
    Sep 2007

    Posted 15 Jan 2014 Link to this post

    Hi Roger,

    First - does your code work on iOS? If the problem is only with Android and if it works in Cordova 3.0 but does not in Cordova 3.2, and you've edited the Android config.xml then you've most likely hit the whitelisting breaking change in Cordova 3.2. For more information refer to our release notes here.

    You've missed the Icenium Visual Studio Integration keynote? It has been recorded and posted here.
    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
  5. Roger
    Roger avatar
    183 posts
    Member since:
    Sep 2007

    Posted 16 Jan 2014 Link to this post

    Hi Steve,
    no nothing like that...I have an application. I added WCF to do the REST with the phone and that works fine. Now I'm getting into PhonGap and the filetransfer. This uses multi-part forms to transfer the file and WCF can't handle multi-part unless you change the binding:
           <binding name="WebConfiguration" 

    of course if I do that all the other REST functions don't work. Without the streamed transfer mode the endpoint is not recognised and that's where I get the file-not-found error....I thought it was the file on the phone, but no.

    So I used an asmx page for a web service to handle the filetransfer POST and that works fine...except that none of the parameters come through (tried params and form collection). I had to add them to the options as a header:

    options.headers = {Connection: "close",
    and get them out the other end via:

    of course you also get the file
    HttpContext.Current.Request .Files(fileKey)

    There's probably other ways to do this (ie add another bindable endpoint to the WCF that uses streaming) but I've spent enough time on this and just need to get the app in the store & this will get me the data I need.

    So it's nothing to do with phonegap  as it works on both Android and Apple.

    Be aware that if you add an asmx page to the solution after the WCF then the WebHTTPBinding will be affected and you'll lose the existing functionality of the WCF REST. I had to restore my solution from a precious endpoint and then copy an existing asmx page and turn it into the endpoint for the filetransfer post.

    The original app is now working fine in all it's REST glory and I have the added functionality of multi-part POST.
    I tried it both in Cordova 3.0 & 3.2 with same result so I'll stick with 3.2
Back to Top