Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I lost many time on non working multi file upload, I was surprised why it's not supported. Moreover, fix is trivial, something like #965

Open
ikzsl opened this issue Oct 23, 2024 · 1 comment

Comments

@ikzsl
Copy link

ikzsl commented Oct 23, 2024

When I lost many time on non working multi file upload, I was surprised why it's not supported. Moreover, fix is trivial, something like

[ContentType.FormData]: (input: any) =>
  Object.keys(input || {}).reduce((formData, key) => {
    const property = input[key];
    if (Array.isArray(property) && property.every(p => p instanceof Blob)) {
      property.forEach(p => formData.append(key, p));
    } else {
      formData.append(
        key,
        property instanceof Blob
          ? property
          : typeof property === 'object' && property !== null
            ? JSON.stringify(property)
            : `${property}`,
      );
    }
    return formData;
  }, new FormData()),

Originally posted by @darky in #815 (comment)

@guatedude2
Copy link

I have a similar issue in React Native but I use uri with local system files so I added one more check:

[ContentType.FormData]: (input: any) =>
  Object.keys(input || {}).reduce((formData, key) => {
    const property = input[key]
    if (Array.isArray(property) && property.every((p) => 'uri' in p)) {
      property.forEach((p) => formData.append(key, p))
    } else if (Array.isArray(property) && property.every((p) => p instanceof Blob)) {
      property.forEach((p) => formData.append(key, p))
    } else {
      formData.append(
        key,
        property instanceof Blob ? property : typeof property === 'object' && property !== null ? JSON.stringify(property) : `${property}`,
      )
    }
    return formData
  }, new FormData()),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants