使用javascript将文件上传到SkyDrive [英] Upload file to SkyDrive using javascript

查看:88
本文介绍了使用javascript将文件上传到SkyDrive的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我正在尝试使用javascript将文件上传到SkyDrive。

I'm trying to upload a file to SkyDrive using javascript.

第一次尝试是使用JQuery的ajax方法。

The first attempt is using the ajax method from JQuery.

          function uploadUsingAjax() {                                                
                $.ajax({
                    type: "PUT",
                    data : "SOMEDATA",
                    url: "https://apis.live.net/v5.0/me/skydrive/files/testfile10.txt?access_token=" + ACCESS_TOKEN,                                                          
                    success: function() { alert('Success!' );},
                    error: function(a,b,c) { alert('Error!' + a + b + c); }
                });                 
            }

这给我一个内部服务器错误。

This gives me a internal server error.

文档说我应该能够使用PUT做到这一点因此避免了使用multipart标头的复杂性。

The documentation says I should be able to do this using PUT and hence avoid the complexity with the multipart headers.

我实际上唯一能用的是使用windows live javascript库中的WL.api方法。

The only thing I actually have working is using the WL.api method from the windows live javascript library.

喜欢这个 

Like this 

            function upload() {
                WL.api({
                    path: "me/skydrive/files/testfile8.txt",
                    method: "PUT",
                    body: "Some file content"
                }, function (response) {onError(response) });

                    function onError(response) {

                    $("#status").html(response.error) 
                    }
                    
            }

这里的问题是文件在SkyDrive上结束为空。 

The problem here is that the file ends up empty on SkyDrive. 

下一次尝试通过WL.api方法使用POST 

Next attempt is using POST through the WL.api method 

         function uploadUsingPost() {
                WL.api({
                    path: "me/skydrive/files",
                    method: "POST",
                    body: createUploadRequestBody()
                }, function (response) { onError(response) });

                function onError(response) {

                    alert(response.error)
                }

            }

            function createUploadRequestBody() {
                var body = "--A300x/r/n"
                + "Content-Disposition: form-data; name='file'; filename='RV.TXT'/r/n"
                + "Content-Type: application/octet-stream/r/n"
                + "This is some content/r/n"
                + "--A300x/r/n";
                return body;
            }

可悲的是,这也不起作用。

Sadly, this does not work either.

知道我在这里做错了吗?

Any idea what I'm doing wrong here?

问候

Bernhard Richter 

Bernhard Richter 




推荐答案

<嗯,我无法重复这个。 您是否能够在IE Developer工具栏中提供Fiddler跟踪或查看网络流量?

Hmm, I'm unable to repro this.  Would you be able to provide a Fiddler trace, or look an network traffic in IE Developer toolbar?


这篇关于使用javascript将文件上传到SkyDrive的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆