2

I am developing a windows store app with Box.net.

I am trying to upload files using backgrounduploader in winRT,

code snippet:

    public async Task<UploadOperation> CreateUploadOperationV2(StorageFile file, string name, string destFolderId)
    {
        BackgroundUploader uploader = new BackgroundUploader();
        uploader.Method = "POST";
        uploader.SetRequestHeader("Authorization", "BoxAuth " + "api_key=" + mykey + "&auth_token=" + mytoken);
        var uploadUrl = "https://www.box.net/api/2.0/"+ "files/content";
        List<BackgroundTransferContentPart> parts = new List<BackgroundTransferContentPart>();
        var part = new BackgroundTransferContentPart("filename", name);
        part.SetFile(file);
        parts.Add(part);
        part = new BackgroundTransferContentPart("folder_id");
        part.SetText(destFolderId);
        parts.Add(part);
        var uploadOperation = await uploader.CreateUploadAsync(new Uri(uploadUrl), parts);
        return uploadOperation; 
    }

It works fine with ascii encoded filename, but failed with others.

In header, it looks like this:

Content-Disposition: form-data; name="filename"; filename*=utf-8''Foo%E8%A4%87.jpg

Can someone help me with this?

I am stucked here for 2 days.

Thanks in advance!

seanhc
  • 73
  • 5

1 Answers1

0

@seanhc, I have this issue. And solved, but I used java. May can help your:

String url = "https://api.box.com/2.0/files/content";
            HttpPost post = new HttpPost(url);
            MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null, Charset.forName("UTF-8"));

            HtmlUtils.addEntity(entity, "folder_id", path.id);
            entity.addPart("filename", new CounterFileBody(post, file, onProgress, breakFlag));
            post.setEntity(entity);

            return BoxComHttpUtils.requestResponse(_storage, post, url);

Start worked correct then I set entity as:

MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null, Charset.forName("UTF-8"));

Find solution here

Community
  • 1
  • 1
Yura Shinkarev
  • 5,134
  • 7
  • 34
  • 57