Some people asked, so I post how I did it. This was done quite quietly, so if you have any comments or something really badly done, I am open to criticism;) The photo is read from the Roll camera and stored in "lastPhoto".
Uploading photos to the S3 server:
Step 1: Creating Data:
_addTextParam() { var textParams = this.state.textParams; s3_upload_id = this.makeid() textParams.push({ name: "key", value: this.state.upload_path + s3_upload_id + '/' + this.state.att_name + ".jpg" }) textParams.push({ name: "AWSAccessKeyId", value: this.state.key }) textParams.push({ name: "acl", value: "public-read" }) textParams.push({ name: "success_action_status", value: "201" }) textParams.push({ name: "policy", value: this.state.policy }) textParams.push({ name: "signature", value: this.state.signature }) textParams.push({ name: "Content-Type", value: "image/jpeg" }) this.setState({ textParams: textParams }); }
Step 2: Submit Data:
_send() { this._addTextParam() var xhr = new XMLHttpRequest(); xhr.open('POST', "http://" + this.state.fs_domain + "." + this.state.server); xhr.onload = () => { this.setState({ isUploading: false }); if (xhr.status !== 201) { AlertIOS.alert( 'Upload failed', 'Expected HTTP 200 OK response, got ' + xhr.status + "/" + xhr.responseText ); return; } if (!xhr.responseText) { AlertIOS.alert( 'Upload failed', 'No response payload.' ); return; } var index = xhr.responseText.indexOf( "http://" + this.state.fs_domain + "." + this.state.server); if (index === -1) { AlertIOS.alert( 'Upload failed', 'Invalid response payload.' ); return; } var url = xhr.responseText.slice(index).split('\n')[0]; this.state.s3_file_id = xhr.responseText.split('Tag>"')[1].split('"')[0] this.state.s3_file_path = xhr.responseText.split('Location>')[1].split('<')[0] this.setState({ isUploading: false }); RCTDeviceEventEmitter.emit('Uploaded') }; var formdata = new FormData(); this.state.textParams.forEach((param) => { formdata.append(param.name, param.value) } ); formdata.append('file', {...this.state.latestPhoto, name: (this.state.att_name+".jpg") }); xhr.send(formdata); this.setState({ isUploading: true }); },
source share