2013-06-20 2 views
1

Rails 앱에서 Paperclip을 사용하여 사진을 업로드하고 S3에 저장합니다. 그래서 저는 그 기능을 iOS 앱에 가져오고 싶었습니다. this gist을 사용하여 내 RubyMotion 앱에서 이미지 업로드를 업로드했지만 놀라 울 정도로 느렸다. Paperclip에서이 날짜 문제를보고 난 후에 다른 접근 방식을 시도했습니다 : https://github.com/thoughtbot/paperclip/issues/254#issuecomment-321507.RubyMotion Formotion 및 BubbleWrap을 사용하여 iOS에서 Rails/S3로 이미지 업로드

그래서 BubbleWrap의 :form_data:format을 사용하고 UIImage.UIImageJPEGRepresentation(@form.render[:photo], 1)을 전달하여 속도가 빨라지는지 확인했습니다. 그러나 그것은 작동하지 않습니다. 내 서버에서 사진 매개 변수를 볼 수 없기 때문에 선택한 사진이 실제로 제대로 렌더링되지 않는 것 같습니다. 그리고 UIImage.UIImageJPEGRepresentation(@form.render[:photo], 1)의 출력이 올바르게 보이지 않습니다.

내 FORMOTION 양식 : 프로파일을 업데이트 할 수

@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'] 
    }] 
    }] 
}) 

내 뽁뽁이의 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 

그래서 내 질문은 : 나는 "(요점 같은 이미지가 .pack으로 제안 M0를 인코딩해야 ")? 내 서버로 전달할 모든 바이너리 데이터로이 프로세스를 빠르게 할 수있는 방법이 있습니까?

답변

2

은 여기 (AFNetworking의 래퍼 인) AFMotion 파일을 업로드 할 수있는 예입니다 .. 더 뽁뽁이로 그런 일을 할 생각하지만 ...

이 없습니다.

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의 문서/예를 살펴 할 수 있습니다 그것이 도움이되기를 바랍니다.

+0

지금은 BubbleWrap에서 AFMotion으로 이동하는 것처럼 보입니다. 감사! – tvalent2

+0

@ tvalent2이 답변이 도움이 될 경우 답변을 허용으로 표시하십시오. – siekfried