簡體   English   中英

在Rails中解碼Base64編碼的文件花費的時間太長

[英]Decoding Base64-encoded file in Rails takes too long

我將圖像文件從Android應用程序發送到我的Rails API。 我使用以下方法解碼圖像:

StringIO.new(Base64.decode64(image[1]))

問題是,這需要太多時間。 在heroku上花費的時間甚至更長。

還有另一種方法可以更快,更有效地做到這一點嗎?

在此處輸入圖片說明

您還可以將其用於解碼base64:

# this method for decode base64 code to file
  def parse_image_data(image[1])
    base64_file = image[1]
    ext, string = base64_file.split(',')

    ext = MIME::Types[base64_file].first.preferred_extension if ext.include?("base64")
    tempfile = Tempfile.new(["#{DateTime.now.to_i}", ".#{ext}"])
    tempfile.binmode
    tempfile.write Base64.decode64(string)
    tempfile.rewind
    tempfile
  end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM