-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react-native): support direct uploads through FormData (#307)
* fix: support direct uploads through FormData under react-native runtime * chore: ignore lgtm warning * chore: dont use word 'triple' in variable name
- Loading branch information
Showing
7 changed files
with
48 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
import { FileTransformer } from './types' | ||
import { identity } from './identity' | ||
|
||
export const transformFile: FileTransformer = identity | ||
export default (): FormData => new FormData() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import * as NodeFormData from 'form-data' | ||
import { FileTransformer } from './types' | ||
import { identity } from './identity' | ||
|
||
export const transformFile: FileTransformer = identity | ||
export default (): NodeFormData | FormData => new NodeFormData() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { BrowserFile, NodeFile } from '../request/types' | ||
import { FileTransformer, ReactNativeAsset } from './types' | ||
|
||
export const transformFile: FileTransformer = ( | ||
file: BrowserFile | NodeFile, | ||
name: string | ||
): ReactNativeAsset => { | ||
if (!file) { | ||
return file | ||
} | ||
const uri = URL.createObjectURL(file) | ||
const type = (file as BrowserFile).type | ||
return { uri, name, type } | ||
} | ||
|
||
export default (): FormData => new FormData() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function identity<T>(obj: T): T { | ||
return obj | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { BrowserFile, NodeFile } from '../request/types' | ||
|
||
export type ReactNativeAsset = { name?: string; type?: string; uri: string } | ||
|
||
export type FileTransformer = ( | ||
file: NodeFile | BrowserFile, | ||
name: string | ||
) => NodeFile | BrowserFile | ReactNativeAsset |