如何使用非ascii文件名上传到Box.net

时间:2012-12-10 08:06:11

标签: windows-store-apps box-api

我正在使用Box.net开发一个Windows应用商店。

我正在尝试使用winRT中的backgrounduploader上传文件,

代码段:

    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; 
    }

使用ascii编码的文件名工作正常,但与其他人一起失败。

在标题中,它看起来像这样:

内容 - 处置:表单数据; NAME = “文件名”;文件名* = UTF-8''Foo%E8%A4%87.jpg

有人可以帮我这个吗?

我被困在这里2天。

提前致谢!

1 个答案:

答案 0 :(得分:0)

@seanhc,我有这个问题。并解决了,但我用java。可以帮助你:

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);

开始工作正确然后我将实体设置为:

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

查找解决方案here