0
AFNetworking Image上傳時出現了一個非常奇怪的問題。文件上傳正確,我可以看到它已經上傳到我的服務器上。當我下載文件並在Mac上打開它時,圖像顯示正常。使用AFNetworking上傳圖片後不顯示在瀏覽器中
但是,相同的圖像不會顯示在瀏覽器上。不知何故,該文件已損壞,無法在瀏覽器上運行。
下面是圖像的link。如果您嘗試在任何瀏覽器中打開,它將顯示空白屏幕。
任何想法爲什麼會發生這種情況?我今天花了幾個小時才弄清楚,但無濟於事。我已經嘗試上傳PDF,它工作正常。
這裏是我的代碼:
NSDictionary *params = @{@"deliverable_ID" : deliverableID,
@"name" : @"Artboard.png",
@"type" : @"png",
@"description" : @"Some random png file"};
NSString *path = [[NSBundle mainBundle] pathForResource:@"Artboard" ofType:@"png"];
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:url parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileURL:[NSURL fileURLWithPath:path] name:@"file" fileName:@"Artboard.png" mimeType:@"image/png" error:nil];
} error:nil];
[request setValue:apiToken forHTTPHeaderField:@"Authorization"];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSURLSessionUploadTask *uploadTask = [manager
uploadTaskWithStreamedRequest:request
progress:nil
completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
if (error) {
NSString * result = [NSString stringWithFormat:@"Error: %@", error];
[delegate printResult:result];
} else {
NSString * result = [NSString stringWithFormat:@"%@", responseObject];
[delegate printResult:result];
}
}];
[uploadTask resume];
嘿,謝謝你的回覆。我不認爲這是問題,雖然...因爲這個圖像:https://ashore-testing.s3.amazonaws.com/uploaded/deliverable97/version1/Artboard.png也有八位字節流內容類型,但顯示在瀏覽器中。然而,當我嘗試捲曲時,奇怪的是 - 我的原始未破碎圖像內容長度是7838,而破壞的圖像內容長度是4629. –
似乎在Obj-C中我的AFNetworking代碼有問題。我嘗試使用PHP上傳(使用multipart/formdata),但圖像不會像這樣被破壞 –