我正在创建面向Windows 8.0
的 Windows 商店应用程序
我在我的 PC 上安装了 Windows 8.1 预览版,我使用 VS2012 创建了应用程序,并使用BackgroundUploader和createUploadFromStreamAsync方法使用以下代码实现了文件上传到服务器 -
string url = //url to upload videostring boundray = string.Format("abcboundry");
String header = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"; filename=\"{2}\"\r\n" + "Content-Type: {3}\r\n\r\n", boundray, "file", source.Name, "application/octet-stream");
string footer = string.Format("\r\n--{0}--\r\n", boundray);
Stream headerStream = GenerateStreamFromString(header);
Stream footerStream = GenerateStreamFromString(footer);
//Stream dataStream = iRandomstream.AsStream();
Stream dataStream = await source.OpenStreamForReadAsync();
MemoryStream fileDataStream = new MemoryStream();
await headerStream.CopyToAsync(fileDataStream);
await dataStream.CopyToAsync(fileDataStream);
await footerStream.CopyToAsync(fileDataStream);
fileDataStream.Position = 0;
IInputStream stream = fileDataStream.AsInputStream();
BackgroundUploader backgroundUploader = new BackgroundUploader();
backgroundUploader.SetRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundray);
backgroundUploader.Method = "POST";
UploadOperation uploadOpration = await backgroundUploader.CreateUploadFromStreamAsync(new Uri(url), stream);
await HandleUploadAsync(uploadOpration, true);
它对我来说工作正常,但是当在安装了 Windows 8.0 的其他系统上进行测试时,由于AccessViolationException 导致崩溃的应用程序未处理。尝试读取或写入受保护的内存。这通常表明其他内存已损坏。”在 InitializeComponent.错误
现在我尝试使用BackgroundTransferContentPart进行分段上传,但这段代码没有成功 -
List<BackgroundTransferContentPart> parts = new List<BackgroundTransferContentPart>();
BackgroundTransferContentPart part = new BackgroundTransferContentPart("file", source.Name);
part.SetHeader("Content-Type", "application/octet-stream");
part.SetFile(source);
parts.Add(part);
BackgroundUploader uploader = new BackgroundUploader();
uploader.Method = "POST";
UploadOperation uploadOp = await uploader.CreateUploadAsync(new Uri(url), parts, "form-data",boundray);
await HandleUploadAsync(uploadOp, true);
我能做些什么来解决我的问题?
如何将大文件上传到服务器?