Created
May 16, 2016 05:27
-
-
Save Obooman/da1137703c47055027c420480df76075 to your computer and use it in GitHub Desktop.
react-native bulit-in tool for image upload
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
export function postData (url, params, fileURL) { | |
let data = new FormData() | |
if (fileURL) { | |
data.append('image', {uri: fileURL, name: 'image.jpg', type: 'image/jpg'}) | |
} | |
_.each(params, (value, key) => { | |
if (value instanceof Date) { | |
data.append(key, value.toISOString()) | |
} else { | |
data.append(key, String(value)) | |
} | |
}) | |
const config = { | |
method: 'POST', | |
headers: { | |
'Accept': 'application/json', | |
'Content-Type': 'multipart/form-data; boundary=6ff46e0b6b5148d984f148b6542e5a5d', | |
'Content-Language': React.NativeModules.RNI18n.locale, | |
'Authorization': 'Token ABCDEF123457890', | |
}, | |
body: data, | |
} | |
return fetch(API_URL + url, config) | |
.then(checkStatusAndGetJSONResponse) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment