Class: Tgios::PhotoUpload
- Inherits:
-
BindingBase
- Object
- BindingBase
- Tgios::PhotoUpload
- Defined in:
- lib/tgios/photo_upload.rb
Instance Method Summary collapse
- #dealloc ⇒ Object
-
#initialize ⇒ PhotoUpload
constructor
A new instance of PhotoUpload.
- #on(event_key, &block) ⇒ Object
- #onPrepareForRelease ⇒ Object
- #upload_s3(fixed_image, get_s3_result, s3_appended_hash = nil, s3_removed_key_arr = nil, &block) ⇒ Object
Methods inherited from BindingBase
#hook, #prepareForRelease, #unhook
Constructor Details
#initialize ⇒ PhotoUpload
Returns a new instance of PhotoUpload.
4 5 6 |
# File 'lib/tgios/photo_upload.rb', line 4 def initialize @events = {} end |
Instance Method Details
#dealloc ⇒ Object
52 53 54 55 |
# File 'lib/tgios/photo_upload.rb', line 52 def dealloc onPrepareForRelease super end |
#on(event_key, &block) ⇒ Object
8 9 10 |
# File 'lib/tgios/photo_upload.rb', line 8 def on(event_key,&block) @events[event_key] = block.weak! end |
#onPrepareForRelease ⇒ Object
46 47 48 49 50 |
# File 'lib/tgios/photo_upload.rb', line 46 def onPrepareForRelease ap 'PhotoUpload clear_all' @events = nil @client = nil end |
#upload_s3(fixed_image, get_s3_result, s3_appended_hash = nil, s3_removed_key_arr = nil, &block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tgios/photo_upload.rb', line 12 def upload_s3(fixed_image, get_s3_result, s3_appended_hash=nil, s3_removed_key_arr=nil, &block) img_data = UIImageJPEGRepresentation(fixed_image, 0.8) s3_params = get_s3_result[:params].dup key = "#{s3_params[:key]}" key.slice!('${filename}') s3_params[:key] = "#{key}#{BubbleWrap.create_uuid}/${filename}" s3_params['Content-Type'] = 'image/jpeg' s3_params.merge!(s3_appended_hash) unless s3_appended_hash.nil? s3_removed_key_arr.each do |key| s3_params.delete(key) end unless s3_removed_key_arr.nil? @client = AFMotion::Client.build(get_s3_result[:url]) do header "Accept", "application/xml" response_serializer :xml end @client.multipart_post('/', s3_params) do |post_s3_result, form_data, progress| if form_data form_data.appendPartWithFileData(img_data, name: "file", fileName:"ios.jpg", mimeType: "image/jpeg") elsif progress @events[:progress].call unless @events[:progress].nil? elsif post_s3_result.success? XMLParser.new.parse_xml(post_s3_result.object,'Key',:delegate) do |s3_key| block.call(true, s3_key) end else block.call(false, post_s3_result) end end end |