0

我尝试上传一张图片(由 FileOpenPicker 选择),但它不起作用。

我的代码:

var openpicker = new FileOpenPicker();
openpicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openpicker.FileTypeFilter.Add(".jpg");
openpicker.FileTypeFilter.Add(".png");
var file = await openpicker.PickSingleFileAsync();

var uploader = new Windows.Networking.BackgroundTransfer.BackgroundUploader();

PasswordCredential pw = new PasswordCredential();
pw.Password = "mypw";
pw.UserName = "user";

uploader.ServerCredential = pw;

uploader.Method = "POST";
var uri = new Uri("ftp://myaddress/Directory/");

var str = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
await uploader.SetSourceStreamAsync(str);
uploader.SetRequestHeader("Filename", "image2.jpg");
var upload = uploader.CreateUpload(uri);

var result = (await upload.StartAsync()).GetResponseInformation().StatusCode;

我在最后一行得到以下异常:

System.Runtime.InteropServices.COMException (0x80072EEF):来自 HRESULT 的异常:
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
处的 0x80072EEF System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotificat‌​ion(任务任务)

0x80072EEF 是 ERROR_INTERNET_LOGIN_FAILURE:

“连接和登录 FTP 服务器的请求失败。”

任何想法我做错了什么?

4

1 回答 1

0

我有同样的问题。尽管这个问题有点老了,但我在寻找答案时被引导到这里。

我发现这里描述的内容对我有用。基本上,BackgroundDownloader 在设置其 ServerCredentials 时似乎失败了......

于 2013-05-10T15:59:40.003 回答