在将许多文件上传到S3时,使用Task.async_stream就好了。
尝试在download_many函数中使用它,该函数包含url和id的关键字列表。当我在iex会话中运行download_many函数时,它返回以下输出:
Package { allow_virtual => true }
class {dummy: }
include dummy
这是功能:
iex(1)> Karma.S3.download_many(1)
#Function<1.112846234/2 in Task.build_stream/3>
#Function<1.112846234/2 in Task.build_stream/3>
指向该文件的链接:https://github.com/karmaradio/karma/blob/async-download_many/lib/S3.ex#L58
我不理解输出:def download_many(_urls) do
urls = [
“5”: “https://engine-image-uploads.s3.amazonaws.com/engine-image-uploads/d4a9f8adb58b4e0b83c47e8f3b21d421-fillable.pdf“,
“3”: “https://engine-image-uploads.s3.amazonaws.com/engine-image-uploads/ccd6d66cb4304b369a025efe3b26e68b-fillable.pdf”
]
ops = [max_concurrency: System.schedulers_online() * 3, timeout: 20000]
tasks = Task.async_stream(urls, &download_with_id/1, ops)
|> Enum.to_list()
IO.inspect tasks
end
def download_with_id({id, url}) do
file_destination = System.cwd() <> “/tmp/altered_document_” <> Atom.to_string(id) <> “.pdf”
download(url, file_destination)
|> Tuple.insert_at(2, id)
end
有没有人经历过类似的事情?
提前致谢!