locked
Not able to upload photo with space in the file name Ex. "Tulip flower.jpg" RRS feed

  • Question

  • Hi,

    We are using following code to upload photos to Skydrive photos. filename without any space uploaded properly. But I am not able to upload file name with space. Please see our code and let us know what needs to be done to fix the issue


            String accessKey = auth.getToken1();
            String fileURL = "https://apis.live.net/v5.0/" + albumId + "/files?access_token=" + accessKey;
            String fileName = photoFile.getName();
            String mimeType = "application/octet-stream"; //MimeTypesFileTypeMap.getMimeType(photoFile.getName());
            String boundary = MultiPartFormOutputStream.createBoundary();

            HttpURLConnection urlConn = null;
            try {
                URL url = new URL(fileURL);
                urlConn = (HttpURLConnection) MultiPartFormOutputStream.createConnection(url);
                urlConn.setRequestProperty("Accept", "*/*");
                urlConn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);

                MultiPartFormOutputStream out = new MultiPartFormOutputStream(urlConn.getOutputStream(), boundary);
                out.writeFile("file", mimeType, "tulip flower.jpg", new FileInputStream(photoFile));
                out.close();

                InputStream in = urlConn.getInputStream();

                JSONObject obj = new JSONObject(in);
                uploadStatus = !obj.has("error");
        }catch(Exception ex) {}

    Wednesday, July 25, 2012 10:27 AM

Answers

  • Hi Ganesan,

    I'm sorry to hear you were having trouble uploading a file to our APIs. I'll be happy to help you but first, it would help me if you could answer a few questions:

    1. What environment (language + OS) are you developing for?
    2. Is it at all possible to record some sort of HTTP trace using a tool such as Fiddler?
    3. Is there a particular reason you chose to use a multipart form POST rather than a generic form POST?

    Our API service should not even be able to return a completely empty JSON object so I suspect the request is not actually being accepted as a valid HTTP message or else it's not actually making it to our service. This would make getting a Fiddler trace an extremely helpful tool for helping you with your problem.

    Thanks,

    Matt VanderKolk

    Thursday, July 26, 2012 6:38 PM

All replies

  • What kind of error are you seeing when you try to upload "tulip flower.jpg"?
    Wednesday, July 25, 2012 7:34 PM
    Moderator
  • I did not get any error. File also not got uploaded. I only got empty jsonObject. File without spaces uploaded properly and for that also I got only empty jsonobject

    Thursday, July 26, 2012 7:41 AM
  • Hi Ganesan,

    I'm sorry to hear you were having trouble uploading a file to our APIs. I'll be happy to help you but first, it would help me if you could answer a few questions:

    1. What environment (language + OS) are you developing for?
    2. Is it at all possible to record some sort of HTTP trace using a tool such as Fiddler?
    3. Is there a particular reason you chose to use a multipart form POST rather than a generic form POST?

    Our API service should not even be able to return a completely empty JSON object so I suspect the request is not actually being accepted as a valid HTTP message or else it's not actually making it to our service. This would make getting a Fiddler trace an extremely helpful tool for helping you with your problem.

    Thanks,

    Matt VanderKolk

    Thursday, July 26, 2012 6:38 PM