gpt4 book ai didi

elixir - phoenix elixir exaws 与 minio 配合使用(上传文件)

转载 作者:行者123 更新时间:2023-12-02 08:15:00 27 4
gpt4 key购买 nike

我正在尝试使用 ExAws图书馆以及 minio 。我尝试上传文件:

filepath
|> S3.Upload.stream_file
|> S3.upload(bucket_name, path)
|> ExAws.request!

我收到一个错误:

[error] #PID<0.1041.0> running Myapp.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /resources/upload
** (exit) an exception was raised:
** (MatchError) no match of right hand side value: %{body: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<InitiateMultipartUploadResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Bucket>user-1</Bucket><Key>docs/tsetup.0.9.51.tar.xz</Key><UploadId>35e9c8b0-ac34-4411-b39b-790a0104df93</UploadId></InitiateMultipartUploadResult>", headers: [{"Accept-Ranges", "bytes"}, {"Server", "Minio/DEVELOPMENT.GOGET (linux; amd64)"}, {"Vary", "Origin"}, {"X-Amz-Request-Id", "K4O7RNNSRLAMSL26"}, {"Date", "Tue, 11 Oct 2016 20:53:58 GMT"}, {"Content-Type", "text/xml; charset=utf-8"}, {"Transfer-Encoding", "chunked"}], status_code: 200}
(ex_aws) lib/ex_aws/s3/upload.ex:39: ExAws.S3.Upload.initialize!/2
(ex_aws) lib/ex_aws/s3/upload.ex:80: ExAws.Operation.ExAws.S3.Upload.perform/2
(ex_aws) lib/ex_aws.ex:41: ExAws.request!/2
(Myapp) web/models/resource.ex:68: Myapp.Resource.put_file_to_cloud/1
(Myapp) web/controllers/resource_controller.ex:59: Myapp.ResourceController.upload/2
(Myapp) web/controllers/resource_controller.ex:1: Myapp.ResourceController.action/2
(Myapp) web/controllers/resource_controller.ex:1: Myapp.ResourceController.phoenix_controller_pipeline/2
(Myapp) lib/Myapp/endpoint.ex:1: Myapp.Endpoint.instrument/4
(Myapp) lib/phoenix/router.ex:261: Myapp.Router.dispatch/2
(Myapp) web/router.ex:1: Myapp.Router.do_call/2
(Myapp) lib/Myapp/endpoint.ex:1: Myapp.Endpoint.phoenix_pipeline/1
(Myapp) lib/plug/debugger.ex:123: Myapp.Endpoint."call (overridable 3)"/2
(Myapp) lib/Myapp/endpoint.ex:1: Myapp.Endpoint.call/2
(plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
(cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4

我从响应中看到文件上传开始。这个迷你返回的答案不符合预期吗?还是问题出在别的地方?

更新:添加 sweet_xml 后现在出现另一个错误:

[error] GenServer #PID<0.593.0> terminating
** (MatchError) no match of right hand side value: nil
(ex_aws) lib/ex_aws/s3/upload.ex:69: ExAws.S3.Upload.upload_chunk!/3
lib/flow/materialize.ex:493: anonymous fn/4 in Experimental.Flow.Materialize.mapper/2
lib/flow/materialize.ex:462: Experimental.Flow.Materialize."-mapper_ops/1-lists^foldl/2-1-"/3
lib/flow/materialize.ex:462: anonymous fn/5 in Experimental.Flow.Materialize.mapper_ops/1
lib/flow/map_reducer.ex:57: Experimental.Flow.MapReducer.handle_events/3
lib/gen_stage.ex:2190: Experimental.GenStage.consumer_dispatch/7
lib/gen_stage.ex:2313: Experimental.GenStage.take_pc_events/3
(stdlib) gen_server.erl:601: :gen_server.try_dispatch/4
(stdlib) gen_server.erl:667: :gen_server.handle_msg/5
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: {:"$gen_consumer", {#PID<0.592.0>, #Reference<0.0.2.533>}, [{<<255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 1, 0, 72, 0, 72, 0, 0, 255, 219, 0, 67, 0, 2, 1, 1, 2, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 5, 3, 3, 3, 3, 3, 6, ...>>, 1}]}
State: {%{#Reference<0.0.2.533> => nil}, %{consumers: [{#Reference<0.0.2.544>, #Reference<0.0.2.546>}], done: [#Reference<0.0.2.533>], done?: false, trigger: #Function<2.69990182/4 in Experimental.Flow.Window.Global.materialize/4>}, {0, 4}, [], #Function<29.77971684/4 in Experimental.Flow.Materialize.mapper_ops/1>}
[error] Ranch protocol #PID<0.587.0> (:cowboy_protocol) of listener Myapp.Endpoint.HTTP terminated
** (exit) an exception was raised:
** (MatchError) no match of right hand side value: nil
(ex_aws) lib/ex_aws/s3/upload.ex:69: ExAws.S3.Upload.upload_chunk!/3
lib/flow/materialize.ex:493: anonymous fn/4 in Experimental.Flow.Materialize.mapper/2
lib/flow/materialize.ex:462: Experimental.Flow.Materialize."-mapper_ops/1-lists^foldl/2-1-"/3
lib/flow/materialize.ex:462: anonymous fn/5 in Experimental.Flow.Materialize.mapper_ops/1
lib/flow/map_reducer.ex:57: Experimental.Flow.MapReducer.handle_events/3
lib/gen_stage.ex:2190: Experimental.GenStage.consumer_dispatch/7
lib/gen_stage.ex:2313: Experimental.GenStage.take_pc_events/3
(stdlib) gen_server.erl:601: :gen_server.try_dispatch/4
(stdlib) gen_server.erl:667: :gen_server.handle_msg/5
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3

同时我看到下载是在wireshark trace ,但是存储文件夹中是空的

我仔细看了Minio的回复,发现有etag:
帧 1138:线路上的 344 字节(2752 位),在接口(interface) 0 上捕获的 344 字节(2752 位)
以太网 II,源:00:00:00_00:00:00 (00:00:00:00:00:00),目标:00:00:00_00:00:00 (00:00:00:00:00: 00)
Internet 协议(protocol)版本 4,源:127.0.0.1,目标:127.0.0.1
传输控制协议(protocol),源端口:9000 (9000),目标端口:42324 (42324),序列:515,确认:1539815,长度:278
超文本传输​​协议(protocol)
HTTP/1.1 200 正常\r\n
接受范围: 字节\r\n
E标记: "2501de281894f7a1f79e8e0d6b8e7d85"\r\n
服务器: Minio/DEVELOPMENT.GOGET (linux; amd64)\r\n
变化: 来源\r\n
X-Amz-请求-Id: M81ULLKCXKH0KRXD\r\n
日期:2016 年 10 月 14 日星期五 15:00:16 GMT\r\n
内容长度: 0\r\n
内容类型:文本/纯文本;字符集=utf-8\r\n
\r\n
[HTTP 响应 2/2]
[自请求以来的时间:0.008850143 秒]
[框架中的上一个请求:1016]
[帧中的上一个响应:1028]
[帧中请求:1032]
UPD:该问题已由 ExAws 库的作者解决 - https://github.com/CargoSense/ex_aws/issues/253

最佳答案

ExAWS 上传期望得到 %{body: %{upload_id: upload_id}} 响应,但您收到的是未解析的 XML 作为正文。 S3 需要 XML 编解码器,因此请确保您已将 XML 解析库 sweet_xml 添加到您的 deps 中。

关于elixir - phoenix elixir exaws 与 minio 配合使用(上传文件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40013954/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com