ios - 在 Swift 4.2 中传递给多部分 API 的非拉丁(多语言)文件名

标签 ios swift multipartform-data

trying to upload the file from iPhone iCloud to the multipart API. When the file name is in English text it shows well after uploading but I do have the file name in another language than English then it is wrong.

在下图中,文件名是中文“ sample .pdf”,但是当我上传它时,作为响应,我得到的文本是“??.pdf”

file name in chinese

后端 API 已经处理了这种转换,因为当我从 Android 上传文件时它可以正常工作。

此外,当我从 textfiled 发送文本时,它会正确显示我应该为字符串做什么?

//上传API调用代码

myRequestData.append("\(MPboundary)\r\n".data(using: String.Encoding.utf8)!)
                // set upload image, name is the key of image
                myRequestData.append("Content-Disposition: form-data; name=\"\(mediaObj!.key)\"; filename=\"\(mediaObj!.fileName)\"\r\n".data(using: String.Encoding.utf8)!)
                myRequestData.append("Content-Type: \(mediaObj!.mimeType)\r\n\r\n".data(using: String.Encoding.utf8)!)
                myRequestData.append(mediaObj!.data!)
                myRequestData.append("\r\n".data(using: String.Encoding.utf8)!)

最佳答案

请将 db filename 字段 collat​​ion 更改为 utf8mb4_unicode_ci 它将被修复,否则您必须在发送 时对其进行编码文件名 并在您的应用程序上显示时对其进行解码。

关于ios - 在 Swift 4.2 中传递给多部分 API 的非拉丁(多语言)文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58875450/

相关文章:

ios - 为什么不能在 drawRect 中更改 UIView 背景颜色?

ios - Swift 3 升级问题转换

ios - Swift:检查 SKActions 的进度

ios - 解析 iOS 中图像下载的多部分响应

objective-c - 从相机胶卷创建一个 UIImages 数组

ios - 使用 Watch 连接框架将数据从 iPhone 传输到 iWatch

ios - iOS 中 Novocaine 的多个音频和设置音量

ios - 带复选标记的自定义表格 View (单元格)

http - 如何测试 multipart/form-data POST 请求

javascript - 将 blob 作为分段上传会导致 500mb 后在 Chrome 上出现 net::ERR_FILE_NOT_FOUND