开发者

Help re-write this Python into Ruby: AJAX POST, decode Base-64, and save

开发者 https://www.devze.com 2023-02-15 11:40 出处:网络
I\'m following a phonegap tutorial and I do not know how to write this \"def iphone_uplo开发者_如何学编程ad \" action in ruby 1.9.2/rails 3.

I'm following a phonegap tutorial and I do not know how to write this "def iphone_uplo开发者_如何学编程ad " action in ruby 1.9.2/rails 3.

http://wiki.phonegap.com/w/page/18270855/Image-Upload-using-JQuery-and-Python

function getPicture_Success(imageData)
{ 
    var feedURL = APIPATH + "photos/iphone-upload/";
    $.post(feedURL, {imageData:imageData}, function(data){
    });
}

In Python (Django):

def iphone_upload(request):
    import base64
    data = base64.b64decode(request.POST.get("imageData"))
    fileout = "/var/www/test.jpg"
    f1 = open(fileout,'wb+')
    f1.write(data)
    f1.close()


def iphone_upload
  @data = request.POST[:imageData].unpack("m")[0]
  fileout = "/var/www/test.jpg"
  File.open(fileout, 'w') {|f| f.write(@data) }
end
0

精彩评论

暂无评论...
验证码 换一张
取 消