Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于上传图片 #14

Closed
tooodooo opened this issue Sep 27, 2016 · 7 comments
Closed

关于上传图片 #14

tooodooo opened this issue Sep 27, 2016 · 7 comments

Comments

@tooodooo
Copy link

之前使用的是 Alamofire ,现在迁到 Pitaya 了

之前是这样上传图片的:

private lazy var uploadImages = [UIImage]()
.
.
.
        Alamofire.upload(
            .POST,
            url,
            multipartFormData: { multipartFormData in

                for i in 0 ..< self.uploadImages.count {
                    let img = self.uploadImages[i]
                    multipartFormData.appendBodyPart(data: UIImageJPEGRepresentation(img, UPLOAD_IMG_QULITY)!, name: "file\(i)", fileName: "file\(i).jpg", mimeType: "image/jpeg")
                }
        }

而Pitaya中上传图片的接口是

Pitaya.build(HTTPMethod: HTTPMethod.POST, url: url)
                .addFiles(<#T##files: [File]##[File]#>)

setHTTPBodyRaw 只能是字符串类型

该如何解决这个问题呢?谢谢

@johnlui
Copy link
Owner

johnlui commented Sep 27, 2016

@tooodooo
Copy link
Author

文档看过了,还没找到解决方法,待上传图片是UIImage类型暂存内存的,不是文件形式

@johnlui
Copy link
Owner

johnlui commented Sep 27, 2016

那把它们写到temp文件夹里不就行啦。。。

@tooodooo
Copy link
Author

目前也只能这样了,建议增加个像Alamofire的multipartFormData方法,开发者就可以省略把图片存储到文件的步骤了:)

@johnlui
Copy link
Owner

johnlui commented Sep 27, 2016

😃 好主意,有空的话欢迎贡献代码呦

@BrikerMan
Copy link
Contributor

@tooodooo 正好遇到这个问题,我来添加一个方法吧。

@BrikerMan
Copy link
Contributor

已添加 #16

@johnlui johnlui closed this as completed Nov 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants