Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function* addImage ({uri, data}) {
// console.log(`ipfs.addImage`)
// console.log(uri)
const file = Platform.OS === 'ios' ? uri.replace('file://', '') : uri
return yield call(addFile, {name: 'file', filename: 'avatar.jpg', type: 'image/jpeg', data: RNFetchBlob.wrap(file)})
}
): Promise {
console.log(
`[Dropbox backup] UPLOADING local file [${localFilePath}] to remote file [${dropboxFilePath}]!`
);
return RNFetchBlob.fetch(
"POST",
DROPBOX.UPLOAD_URL,
{
Authorization: `Bearer ${dropboxAccessToken}`,
"Content-Type": "application/octet-stream",
"Dropbox-API-Arg": JSON.stringify({
path: dropboxFilePath,
mode: "overwrite"
})
},
RNFetchBlob.wrap(localFilePath)
).then((fetchBlobResponse: any) => {
console.log("[Dropbox backup] UPLOAD response!", fetchBlobResponse);
// Ensure we have `data` and a 200 response
if (
fetchBlobResponse.data &&
fetchBlobResponse.respInfo &&
fetchBlobResponse.respInfo.status === 200
) {
console.log("[Dropbox backup] UPLOAD SUCCESS!");
// Record `client_modified` timestamp
const responseData = JSON.parse(fetchBlobResponse.data);
const clientModifiedTimestamp =
responseData[DROPBOX.CLIENT_MODIFIED_TIMESTAMP_KEY];
console.log(
"[Dropbox backup] logging most recent backup timestamp as: " +
clientModifiedTimestamp
const token = tokenData.data.token;
const key = tokenData.data.key;
const PATH = iOS ? response.uri.replace('file:///', '') : response.uri;
const params = [
{
name: 'token',
data: token
},
{
name: 'key',
data: key
},
{
name: 'file',
filename: 'file',
data: RNFetchBlob.wrap(PATH)
}
];
console.log('params', params);
return await upLoadImage(params);
};
uploadPhoto = async () => {
const { photos, index } = this.state;
if (index !== null) {
const { uri } = photos[index].node.image;
const filenameiOS = photos[index].node.image.filename;
const filenameAndroid = await RNFetchBlob.wrap(uri);
this.uploadPhotoToS3(uri, Platform.OS === 'ios' ? filenameiOS : filenameAndroid);
} else {
Alert.alert(
'Oops',
'Please select a photo',
[{ text: 'OK', onPress: () => console.log('OK Pressed') }],
{ cancelable: false },
);
}
};
async function uploadVoiceMessage(file, post) {
const fileData = buildFileUploadData(file);
const headers = {
Authorization: `Bearer ${Client4.getToken()}`,
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'multipart/form-data',
'X-CSRF-Token': Client4.csrf,
};
const fileInfo = {
name: 'files',
filename: encodeHeaderURIStringToUTF8(fileData.name),
data: RNFetchBlob.wrap(file.localPath.replace('file://', '')),
type: fileData.type,
};
const data = [
{name: 'channel_id', data: post.channel_id},
{name: 'client_ids', data: file.clientId},
fileInfo,
];
Client4.trackEvent('api', 'api_files_upload');
const certificate = await mattermostBucket.getPreference('cert');
const options = {
timeout: 10000,
certificate,
};
uploadProfileImage = async () => {
const {profileImage} = this.state;
const {currentUser} = this.props;
const fileData = buildFileUploadData(profileImage);
const headers = {
Authorization: `Bearer ${Client4.getToken()}`,
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'multipart/form-data',
'X-CSRF-Token': Client4.csrf,
};
const fileInfo = {
name: 'image',
filename: encodeHeaderURIStringToUTF8(fileData.name),
data: RNFetchBlob.wrap(profileImage.uri.replace('file://', '')),
type: fileData.type,
};
const certificate = await mattermostBucket.getPreference('cert');
const options = {
timeout: 10000,
certificate,
};
return RNFetchBlob.config(options).fetch('POST', `${Client4.getUserRoute(currentUser.id)}/image`, headers, [fileInfo]);
};
uploadFile = async (file) => {
const {channelId} = this.props;
const fileData = buildFileUploadData(file);
const headers = {
Authorization: `Bearer ${Client4.getToken()}`,
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'multipart/form-data',
'X-CSRF-Token': Client4.csrf,
};
const fileInfo = {
name: 'files',
filename: encodeHeaderURIStringToUTF8(fileData.name),
data: RNFetchBlob.wrap(file.localPath.replace('file://', '')),
type: fileData.type,
};
const data = [
{name: 'channel_id', data: channelId},
{name: 'client_ids', data: file.clientId},
fileInfo,
];
Client4.trackEvent('api', 'api_files_upload');
const certificate = await mattermostBucket.getPreference('cert');
const options = {
timeout: 10000,
certificate,
};