gpt4 book ai didi

Swift:使用 alamofire 上传时图像源中出现内容处置

转载 作者:行者123 更新时间:2023-11-30 10:27:54 26 4
gpt4 key购买 nike

我正在使用以下代码在天蓝色服务器上上传图像文件,成功上传文件。 (我可以在服务器上看到它)

self.manager.upload(multipartFormData: { (multipart) in

multipart.append(fileData, withName: "file",fileName: "uploading.png" , mimeType: "image/png")

}, to: url.description, method: .put, headers: ["x-ms-blob-type":"BlockBlob","Content-type": "multipart/form-data","Content-Disposition" :"form-data"]) { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.response { answer in
print("statusCode: \(String(describing: answer.response?.statusCode))")
comp(true,"Documnet Uploaded Successfully")
}

upload.uploadProgress { progress in
//call progress callback here if you need it
}
case .failure(let encodingError):
print("multipart upload encodingError: \(encodingError)")
comp(false,"Unable to Upload the documnet")
}
}

但是当我下载文件时(手动或通过代码)。图片打不开。它说的是

It may be damaged or use a file format that Preview doesn’t recognise.

当我在记事本中打开文件时。以下线条出现在每张上传图像的顶部。如果没有这些行,文件就“正常”。我不知道为什么每次都会自动添加这些。

--alamofire.boundary.5243a11a13e8a8f4

Content-Disposition: form-data; name="file"; filename="uploading.png"

Content-Type: image/png

请提出解决方案。

最佳答案

不是直接答案,但这里有一些建议您可以看看。

1.在上传到azure之前检查图像是否正常。

2.通过代码上传到azure后,检查是否可以在azure门户中查看正确的图像内容(在azure门户中-> blob存储->单击图像->然后选择编辑)。

3.我认为根本原因可能是由于错误的请求 header 。

通过代码将图片上传到azure时,请使用fiddler等工具检查其请求/响应 header 。

然后手动将图像上传到azure,还使用fiddler检查其请求/响应 header 。

然后您可以比较 header (代码与手动),找出不同之处,然后您可以相应地对代码进行一些更改。

关于Swift:使用 alamofire 上传时图像源中出现内容处置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59750944/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com