gpt4 book ai didi

ios - RubyMotion 使用 Formotion 和 BubbleWrap 将图像从 iOS 上传到 Rails/S3

转载 作者:行者123 更新时间:2023-11-29 10:58:27 25 4
gpt4 key购买 nike

在我的 Rails 应用程序中,我使用 Paperclip 上传照片并将它们存储在 S3 中。所以我想将该功能引入我的 iOS 应用程序。我使用 this gist 将图像上传到我的 RubyMotion 应用程序中, 但速度非常慢。在 Paperclip 中看到这个过时的问题后,我尝试了一种不同的方法:https://github.com/thoughtbot/paperclip/issues/254#issuecomment-321507 .

所以我尝试使用 BubbleWrap 的 :form_data :format 并传递 UIImage.UIImageJPEGRepresentation(@form.render[:photo], 1)相反,看看这是否会加快速度。但是它不起作用。似乎无论选择什么照片实际上都没有正确渲染,因为我在我的服务器中没有看到任何照片参数。 UIImage.UIImageJPEGRepresentation(@form.render[:photo], 1) 的输出看起来不正确。

我的表格:

@form = Formotion::Form.new({
title: "Settings",
sections: [{
title: "Personal Information",
rows: [{
title: "Photo",
type: :image,
key: :photo,
value: @profile_photo
}, {
title: "Name",
type: :string,
placeholder: "Name",
key: :name,
value: @profile['name']
}]
}]
})

我的 BubbleWrap PUT 更新配置文件:

profile_photo = UIImage.UIImageJPEGRepresentation(@form.render[:photo], 1)

data = {
'profile[name]' => @form.render[:name],
'profile[photo]' => profile_photo,
'user[api_token]' => CONFIG.user.api_token,
_method: 'PUT'
}

BW::HTTP.post("#{DEFAULT_URL}/profiles/#{CONFIG.user.profile_id}", { format: :form_data, payload: data }) do |response|
parsed_response = BW::JSON.parse(response.body.to_str)
if response.ok?
@data = parsed_response
self.dismissViewControllerAnimated(true, completion:lambda { parent.load_profile() })
else
App.alert("#{parsed_response.first}")
end
end

所以我的问题是:我必须像 gist 建议的那样用 .pack("m0") 对图像进行编码吗?有没有一种方法可以使用我传递到服务器的所有二进制数据来加快此过程?

最佳答案

我不知道用 BubbleWrap 做这样的事情但是......

.. 这是一个使用 AFMotion(它是 AFNetworking 的包装器)上传文件的示例。

client = AFMotion::Client.build("your endpoint") do
header "Accept", "application/json"
operation :json
end

image = my_function.get_image
data = UIImagePNGRepresentation(image)

client.multipart.post("avatars") do |result, form_data|
if form_data
# Called before request runs
# see: https://github.com/AFNetworking/AFNetworking/wiki/AFNetworking-FAQ
form_data.appendPartWithFileData(data, name: "avatar", fileName:"avatar.png", mimeType: "image/png")
elsif result.success?
...
else
...
end
end

您可能想查看 AFMotion 的文档/示例 here

希望对您有所帮助。

关于ios - RubyMotion 使用 Formotion 和 BubbleWrap 将图像从 iOS 上传到 Rails/S3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17203324/

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