vue-upload-component icon indicating copy to clipboard operation
vue-upload-component copied to clipboard

Using thread only uploads a single image

Open Gray93 opened this issue 5 years ago • 0 comments

I am using the upload component as part of a v-dialog, I am trying to upload multiple files in a single call to the server, this is how I came across the thread property.

If I do not use thread, it will call the server multiple times only ever with one file in the request form - it does however upload them all successfully. If I add thread, it calls the server once - but still the request form only includes a single file.

I have already followed the advice in a previous case (I think #44) where you recommended uninstalling and reinstalling due to some issues with HTML 4 but that unfortunately didn't solve my problem.

Any help would be gratefully received.

Here is my file upload setup:

<file-upload
     :post-action= postEndPoint
     :multiple="true"
     :drop="true"
     :drop-directory="true"
     :maximum="5"
     accept="image/*"
     @input-filter="inputFilter"
      v-model="files"
      ref="upload"
></file-upload>

Here is my end point:

        public async Task<string> UploadResources(string p_assetDetailid)
        {
            return await _ResourceService.UploadAssetResources(p_assetDetailid, Request.Form);
        }

And here is the service for handling the upload:

public async Task<string> UploadAssetResources(string p_assetDetailid, IFormCollection p_form)
        {
            var assetDetails = GetAsset(p_assetDetailid);

            foreach(var file in p_form.Files)
            {
                var item = file;

                using (var ms = new MemoryStream())
                {
                    item.CopyTo(ms);
                    var fileBytes = ms.ToArray();
                    var extension = Path.GetExtension($"{file.FileName.Replace(" ", "_")}");

                    var resource = new Resource(GetResourceType(extension),
                        $"{file.FileName.Replace(" ", "_")}",
                        p_assetDetailid);

                    var url = await _Storage.StoreBytes(_containerName,
                        $"{resource.id}{extension}",
                        fileBytes);

                    resource.Update(url);
                    resources.Add(resource);
                }
            }
            await _AssetDetails.UpdateAsync(assetDetails);

            return "Success";
        }

Gray93 avatar Nov 13 '19 11:11 Gray93