Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

[feat] support metadata for uploadFile #264

Open
kyoz opened this issue Jun 10, 2022 · 1 comment · May be fixed by #265
Open

[feat] support metadata for uploadFile #264

kyoz opened this issue Jun 10, 2022 · 1 comment · May be fixed by #265

Comments

@kyoz
Copy link

kyoz commented Jun 10, 2022

Is your feature request related to a problem? Please describe.

Some backend require not just params but some metadata that come with the files.

Like the Google Drive API. To upload a file to appDataFolder, I have to provide file name and parents (folder) as file's metadata

Ex:

{
      parents: ['appDataFolder'],
      name: 'backup.json',
},

Just like in this plugin

Is there any way to archive with current version. I'v look through the docs but there's seem nothing like that.

There is data option, i'v tried but it seem doesn't work :'(

Describe the solution you'd like
Have option to add metadata for file when upload

Something like this, maybe:

const options = {
      url: `${fileUploadUrl}?uploadType=media`,
      name: 'backup.db',
      filePath: backupFileUrl,
      fileDirectory: Directory.Documents,
      headers: {
        'Authorization': `Bearer ${this.accessToken}`,
      },
      metadata: {
        name: 'backup.db',
        parents: ['appDataFolder']
      },
      progress: true,
};

Http.uploadFile(options).then(res => {
...
@kyoz
Copy link
Author

kyoz commented Jun 11, 2022

Currently, I somehow can make this work by adding some code.

        data.append("\r\n--\(boundary)\r\n".data(using: .utf8)!)
        data.append(
          "Content-Disposition: form-data; name=\"\(name)\"; filename=\"\(fname)\"\r\n".data(
            using: .utf8)!)
--------->
        data.append("Content-Type: application/json; charset=UTF-8)\r\n\r\n".data(using: .utf8)!)
        data.append("{\"parents\":[\"appDataFolder\"],\"name\":\"backup.db\"}\r\n\r\n".data(using: .utf8)!)
        data.append("\r\n--\(boundary)\r\n".data(using: .utf8)!)
<---------
        data.append("Content-Type: \(mimeType)\r\n\r\n".data(using: .utf8)!)
        data.append(fileData)
        strings.forEach { key, value in
            data.append("\r\n--\(boundary)\r\n".data(using: .utf8)!)
            data.append("Content-Disposition: form-data; name=\"\(key)\"\r\n\r\n".data(using: .utf8)!)
            data.append(value.data(using: .utf8)!)
        }

@thomasvidas How do you think 'bout this. I think it's some how require for common use cases these days. Please confirm so I can make a PR with metadata param as an object.

@kyoz kyoz linked a pull request Jun 13, 2022 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant