Uploading File Permissions needed?

38 views
Skip to first unread message

tiago...@alidata.com.pt

unread,
Jan 22, 2014, 12:30:10 PM1/22/14
to codenameone...@googlegroups.com
Hello everyone,

I've developed an application that at some point gives user the possibility to upload a file to a server using webservices. Users can either use mobile fileSystem files, or they can use mobile camera to take pictures and upload them too.

So far is that I had no problems with this.

Today my coworker realized that when uploading using his device files were being stored with 1KB on our server. Doing the same on other phones lead to a successful result and correct files.
So, the only difference we spotted was that his Android version was 4.2.2 and nobody else had that version.

I'm not sure if problem is on codename application but here's a funny fact:
If he tries to upload a file directly from / generated on his smartphone, it is created on server with 1KB size.
If he passes a file to his SD Card from his computer and uploads it, it is created correctly on server.

This is odd I think. What do you guys think could cause this strange behavior?

Here's my uploadFile code:
    private void uploadFile(String file)
    { 
        MultipartRequest req = new MultipartRequest();
        req.setUrl(URL);
        req.setPost(true);
        InputStream is = null;
        try {
            is = FileSystemStorage.getInstance().openInputStream(file);
            req.addRequestHeader("userID", user.getUserID());
            req.addRequestHeader("printerID", user.getDefaultPrinter());
            req.addData("content", is, FileSystemStorage.getInstance().getLength(file), "text/plain");
            req.setFilename("content", "ExampleName);
            InfiniteProgress prog = new InfiniteProgress();
            Dialog dlg = prog.showInifiniteBlocking();
            req.setDisposeOnCompletion(dlg);
            NetworkManager.getInstance().addToQueueAndWait(req);
        } catch (IOException ioe) { 
            System.out.println("ERROR WHILE UPLOADING");
        }
    }

Thanks in advance

Shai Almog

unread,
Jan 22, 2014, 1:52:40 PM1/22/14
to codenameone...@googlegroups.com, tiago...@alidata.com.pt
Hi,
probably an Android permission thing. You need the files to be in the app directory in order for them to be accessible.

tiago...@alidata.com.pt

unread,
Jan 22, 2014, 1:58:48 PM1/22/14
to codenameone...@googlegroups.com, tiago...@alidata.com.pt
Hi,

So there is no way I can solve this problem?
Because I have a filetree and user choses the file he wants to upload from that filetree. If app can't access it, shouldn't those files not be displayed?

Thanks

Shai Almog

unread,
Jan 23, 2014, 12:40:15 AM1/23/14
to codenameone...@googlegroups.com, tiago...@alidata.com.pt
Hi,
I'm not really sure about this. We generally use list() on the java.io.File API which doesn't indicate to us if the file can be opened by the user or not.
If you are just looking for Image's you should use the gallery API and not the file chooser API. The problem is that the FileSystemStorage API is very platform specific and every OS has its own "oddities" in this regard.
Reply all
Reply to author
Forward
0 new messages