- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 AFNetworking 上传文件和AFAmazonS3Client到亚马逊S3。我循环遍历一个文件数组,所有文件都按预期成功上传到 S3 服务器,但在上传过程中,每个文件中都添加了不应该存在的额外内容。例如。添加到名为 kmeans.sh 的文件中的文本如下所示:
--Boundary+0xAbCdEfGbOuNdArY
Content-Disposition: form-data; name="file"; filename="kmeans.sh"
Content-Type: application/octet-stream
这种内容出现在每个文件的顶部。我的上传方法如下:
NSMutableURLRequest *request = [self
multipartFormRequestWithMethod:method
path:destination
parameters:parameters
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:data
name:@"file"
fileName:[fileURL.path lastPathComponent]
mimeType:self.mimetype];
}];
我在这里做错了什么,向我的文件添加了额外的信息?我真的不知道如何解决这个问题,并且我很感谢我可以尝试的任何建议。
更新:最初我按照 Matt 的建议做了,但我使用了 PUT 方法而不是 POST。今天我下载了最新版本的 AFAmazonS3Client 并尝试使用以下方法使用 PUT 和 POST 上传文件:
postObjectWithFile:(NSString *)path destinationPath:(NSString *)destinationPath parameters....
putObjectWithFile:(NSString *)path destinationPath:(NSString *)destinationPath parameters....
对于上传到存储桶 objcs3 且前缀为“Site3/hei/”的文件“Lima1996.pdf”,stringToSign 如下所示: 发布
multipart/form-data; boundary=Boundary+0xAbCdEfGbOuNdArY
Thu, 06 Jun 2013 00:37:04 GMT
/objcs3/Site3/hei/Lima1996.pdf
请求如下所示:
auth: {
"Accept-Language" = "en;q=1, nb;q=0.9";
Authorization = "removed";
"Content-Length" = 915478;
"Content-Type" = "multipart/form-data; boundary=Boundary+0xAbCdEfGbOuNdArY";
Date = "Thu, 06 Jun 2013 00:37:04 GMT";
"User-Agent" = "connectCloudTest/1.0 (Mac OS X Version 10.8.4 (Build 12E55))";
}
一切看起来都不错,但是当我使用 POST 方法上传文件时,我不断收到错误消息
Upload failed Expected status code in (200-299), got 405 (-1011)
使用 PUT 方法会导致之前的错误,即上传成功,但内容因额外的 header 信息而出现乱码,如原始问题所示。非常感谢您的建议!
感谢您的帮助!干杯,特隆德
最佳答案
通过替换AFAmazonS3Client中的putObjectWithMethod
,我成功上传了我的文件,没有任何额外的 header 。与:
(void)putObjectWithMethod:(NSString *)method
file:(NSString *)filePath
destinationPath:(NSString *)destinationPath
parameters:(NSDictionary *)parameters
progress:(void (^)(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))progress
success:(void (^)(id responseObject))success
failure:(void (^)(NSError *error))failure
{
NSMutableURLRequest *filerequest = [NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]];
[filerequest setCachePolicy:NSURLCacheStorageNotAllowed];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:filerequest returningResponse:&response error:&error];
if (data && response) {
NSMutableURLRequest *request = [super requestWithMethod:@"PUT" path:destinationPath parameters:nil];
[self authorizeRequest:request withPath:destinationPath];
[request setHTTPBody:data];
AFHTTPRequestOperation *requestOperation = [self HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
if (success) {
success(responseObject);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (failure) {
failure(error);
}
}];
[requestOperation setUploadProgressBlock:progress];
[self enqueueHTTPRequestOperation:requestOperation];
}
}
我不知道为什么我的 POST 方法从来没有工作过,但是使用 PUT 一切都工作得很好。干杯,特隆德
关于cocoa - AF网络上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16926165/
我是 ADF faces 的新手,在 af:selectOneChoice 的值更改上部分触发 af:panelAccordion 时遇到麻烦。 af:panelAccordion 在其 af:sho
我有一个非常简单的没有支持 bean 的 jspx:
我正在使用 wordpress 4.9.7我正在使用 advanced custom fields 4.4.12 . 在我的后端,我有一个名为 coins 的帖子类型,其中有一个名为 related_
如何更改 UIImageview 上图像显示的大小,我正在使用 AFNETWORKING 下载图像,它适合 UIImageView 的大小。 但我只想显示图像的一半,就像 Facebook 应用程序中
我有这样一个字符串: '(459..521),(1834..2736)' 我想让它看起来像这样: [(459, 521), (1834, 2736)] 也就是说,一个包含值的元组列表,而不是字符串。
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
我目前正在从事一个涉及音频流的项目。由于版权问题,我必须限制同时访问该文件的人数,但谷歌并不是我寻找合适解决方案的 friend 。我的站点(在 WordPress 上运行,因此在 PHP 和 mys
我的主要编程语言,j ,最近开源了。为了改进它,我正在研究用 C 编写的源代码。 但自从我阅读或编写 C 以来已经有很长(!)的时间了,那时我什至都不擅长。这个特定代码库的编写方式是......特殊的
我正在尝试进行自定义缩混转换,大致相当于: ffmpeg -y -i "file.mkv" \ -map 0:1 -c:0 flac -ac:0 4 \ -map 0:3 -c:1 flac -a
ffmpeg 无法识别“-af”选项。我怎样才能解决这个问题? $ ffmpeg -i 01.wav -af pan=1:c0=c1 01mono.wav ffmpeg version 0.10.12
我用来获取日期输入。当日历弹出时,我想将其移动到左侧(从屏幕左侧开始)。这可行吗?如果是这样,如何控制? 谢谢,肖恩 最佳答案 您没有 af:inputDate 的控件,该控件根据屏幕限制和可用空间决
有谁知道如何根据特定属性过滤日历事件? 例如,基于提供商 ID 或其他内容。我想要的是有一些复选框,通过选中这些复选框,日历事件将相应地显示。 最佳答案 使用 View Object View Cri
我有处理位置数据的代码,因此我可以提取可以匿名化数据的详细信息——例如,如果我的地点 API 说它是 _type:“Building”和 building:“Safeway”——我可以保存数据作为纬度
我需要来自使用 Alamofire 的 Post 请求调用的 json 响应的数据,但由于某种原因我无法访问该数据 我尝试跟随 Alamofire github 文档以及这篇文章 get data f
我的页面中有一个,但我不希望输入文本旁边有日历图标。如何删除该日历图标? 谢谢,肖恩 最佳答案 您可以通过自定义 Oracle ADF 皮肤 CSS 来隐藏日历图标: https://docs.ora
我收到此错误已有 2 天了。我已阅读有关相同错误的任何链接,但每次都没有效果。 我正在尝试简单的继承这是我的 employee.py 文件 class Employee(models.Model):
我是 Android 编码和这个论坛的新手。当我尝试运行项目来测试它时,我收到以下错误:- "app_name" is not translated in af, am, ar, be, bg, ca
我想要完成的是: 如果我的整个工作表中 AC-AF 列中的任何单元格为空白,请剪切整行并粘贴到标有“MissingShipping”的新工作表中。 代码应该根据行数进行调整,因为这永远不会相同。 从我
如何从 AF 列及以后读取 Excel 文件?我不知道最后一列字母名称,而且文件太大,无法不断检查。 df = pd.read_excel(r"Documents\file.xlsx", usecol
我正在使用 OSIsoft AF SDK 版本 4。 添加引用后,一切工作正常,Visual Studio 可以看到 OSISoft 命名空间和所有内容。但是当我尝试构建时,我在输出窗口中收到此错误并
我是一名优秀的程序员,十分优秀!