Skip to content

Instantly share code, notes, and snippets.

@coolvasanth
Created August 27, 2017 05:59
Show Gist options
  • Save coolvasanth/d042a26deda75f5e390b42b87995f30d to your computer and use it in GitHub Desktop.
Save coolvasanth/d042a26deda75f5e390b42b87995f30d to your computer and use it in GitHub Desktop.
Uploading a file from google drive/cloud application into your server Ionic, Hybrid app development.
//You need to use html input type file for this purpose.
// INPUT TYPE FILE GIVES A WEIRD LOOK FOR APP SO I HAVE
//STYLED IT LIKE BELOW.
//the html code is as below ex home.html
<label ion-button for="uploadResume" block style="background-color: #16a085;color: white;" color="secondary">Choose Resume</label>
<input style="display: none;" type="file" name="" id="uploadResume" (change)="OnResumeSelect($event)">
//In home.ts add below code
public OnResumeSelect(fileInput: any) {
var file = fileInput.target.files[0];
this.fd = new FormData();
// JUST APPEND EVERY OTHER DATA THAT YOU WANT IT TO COME WITH THE
//CHOOSEN FILE, LIKE NAME,PH NO ETC
this.fd.append("upresume_one", file);
//BELOW IS THE CODE FOR SENDING THAT FILE TO YOUR CUSTOM SERVER
var xhr = new XMLHttpRequest();
self.progressDialog.presentLoading();
xhr.open('POST', 'YOUR API', true);
xhr.onload = function() {
if (xhr.status == 200) {
self.progressDialog.dismissLoading();
var resp = JSON.parse(xhr.response);
console.log('Server got: ', resp);
console.log('Server got: ', resp.message);
if(resp.success == 1)
{
console.log("THIS IS SUCCESS")
}
else{
self.showalert.presentAlert("Error",resp.message)
self.progressDialog.dismissLoading();
return
}
};
}
xhr.send(this.fd);
}
@HardikDG
Copy link

Didn't find anything specific to google drive. it's just mainly very basic sample of how to select a file and convert it to send in XHR request

@coolvasanth
Copy link
Author

@HardikDG what your exactly looking at ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment