Skip to content

Cannot modify the fileRecord in upload handler #53

@jigarzon

Description

@jigarzon

Hi, after uploading, I need to update the url property in the fileRecord object, in order to store in my database the fileRecord with all the information needed to see the files later (as commented in the section "Demo 1. Preloading Existing Files" of the documentation).

I try to modify the fileRecord object in this way:

uploaded(ev) {
      var files = Array.isArray(ev) ? ev : [ev]
      for (var file of files) {
        var respObj = JSON.parse(file.request.response)
        var backendResponse = respObj.result.files.file[0]   //this is the way my backend returns it
        if (fileObj) {
          file.fileRecord.url = backendResponse.url
        }
        
      }
    },

The problem is that after modifying the fileRecord, it's not reflected in the v-model instance (the files have no url set)
I even tried to make something more complex: finding the specific file in the model and updating it manually... but it still doesn't work:

 uploaded(ev) {
      var files = Array.isArray(ev) ? ev : [ev]
      for (var file of files) {
        var respObj = JSON.parse(file.request.response)
        var backendResponse = respObj.result.files.file[0]
        var fileRecord = this.fileRecords.find(
          f => f.upload.data.result.files.file[0].name === backendResponse.name
        )
        if (fileRecord) {
          fileRecord.url =backendResponse.url
        }
      }

    },

What is the common way of resolving this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions