我正在使用mattt的AFAmazonS3Manager library将图像发布到Amazon S3,基本上遵循那里的示例。上传工作正常,但是当我从S3下载文件时,它有那些使文件无效的标题。
--Boundary+37BFEC640AAEA6AB
Content-Disposition: form-data; name="key"
test.png
--Boundary+37BFEC640AAEA6AB
Content-Disposition: form-data; name="file"; filename=".png"
Content-Type: image/png
âPNG
IHDR,êu]{iDOT»(»»-0∫´@IDATx\ΩÂü◊πÆ≠ø‚ÏΩOíùƒ(ã,Àñôb;vσÃ33Ãh4ÃÃÑC›”√åb∂d…≤dvñ„Äì≥˜9ÔóÁΩÓUS≤≤?<øµ™jUUwO◊’˜kÕ¨≥Côv~4«Nd⁄©¡,,€NÂÿÒ˛l;÷ómSΩÖnH¥ÜÚ8k≠I¥æñTÌÃ≤Èû
...
当我删除标题时,文件变为有效,我可以使用预览或Photoshop打开它。
创建图像的代码如下:
// Save image to Amazon S3. Save URL for user dictionary.
NSData *pngImage = UIImagePNGRepresentation(profilePicture);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imagePath =[documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", chatIdString]];
if ([pngImage writeToFile:imagePath atomically:NO]) {
NSLog(@"Successfully cached profile picture to %@.", imagePath);
AFAmazonS3Manager *s3Manager = [[AFAmazonS3Manager alloc] initWithAccessKeyID:AWSAccessKeyId secret:AWSSecretKey];
s3Manager.responseSerializer = [AFOnoResponseSerializer XMLResponseSerializer];
s3Manager.requestSerializer.region = AFAmazonS3USStandardRegion;
s3Manager.requestSerializer.bucket = @"checkchat";
[s3Manager.requestSerializer setValue:@"image/png" forHTTPHeaderField:@"Content-Type"];
[s3Manager putObjectWithFile:imagePath...
我正在使用PUT请求,根据Amazon S3的REST API参考。知道如何在S3上存储有效图像吗?