【发布时间】:2017-12-30 21:01:16
【问题描述】:
我正在我的应用中实现 React 版本的 FineUploader 以将文件上传到 Azure Blob 存储。
确定文件已上传后,我需要将其信息保存在我的后端数据库中。我不想在我的数据库中注册文件信息,除非我知道文件在我的 blob 存储中。这是我需要获取的信息:
- 原始文件名
- 分配
blobName或uuid - 如果可以的话,文件大小信息也会非常有用,但不是必须的
如果我正确阅读了文档,blobProperties 似乎是我获取此信息的正确位置,但到目前为止我还无法使其正常工作。
在blobProperties 中,我不需要调用我的数据库来获取 blobName。我可以分配一个简单的GUID 值,或者简单地捕获uuid FineUploader 分配的值。我只想捕获我需要的信息并将它们存储在我的 Redux 存储中。
这是我需要帮助的地方:
const uploader = new FineUploaderAzure({
options: {
blobProperties: function(id) {
// How do I get original file name here?
// If I can, I'd like to get file size as well.
// Once I know file's original name as well as the blobName assigned to it, I'll store them in my Redux store
},
cors: {
expected: true,
sendCredentials: false
},
signature: {
endpoint: 'http://myapp.com/api/getsas'
},
request: {
endpoint: 'https://myaccount.blob.core.windows.net/my-container'
},
callbacks: {
onComplete: function (id, name, responseJSON, xhr) {
myFunction(responseJSON);
}
}
}
})
const myFunction = (responseJSON) => {
// If upload is successful, I'll get file details from Redux store and call my action creators
// to trigger an API call to my backend so that I can register uploaded files in my database.
}
我很感激有关如何获取我正在寻找的文件信息的一些指示。
【问题讨论】:
-
我的理解是你在服务器中构建json响应,像这样:return Json(new { status = "success", fileName = "MyFileName" }); - 你是如何构建你的 responseJSON 的?
-
我直接上传到 Azure Blob 存储,所以在文件上传后我不会访问我的服务器。这个想法是在我点击
onComplete后准备我的服务器请求,但也许我没有遵循规定的方式。 -
为了进一步澄清,我的意图是在上传完成后捕获上传的文件信息,然后对我的服务器进行 API 调用以将上传的文件信息存储在我的后端数据库中。这不是正确的工作流程吗?
标签: javascript reactjs fine-uploader