Upload pdf file from local to service api


#1

hi, I’m new to Ionic. Currently, i’m working on mobile apps where i need to upload a pdf file from any file in the mobile to the service api. I’ve already installed file transfer plugin and file opener plugin and i looked at the coding from ionic framework. but i’m kind of lost right now. don’t know how to apply it.

uploadDocument(){
const fileTransfer: FileTransferObject = this.transfer.create();
let options: FileUploadOptions = {
fileKey: ‘file’,
fileName: ‘name.pdf’,
headers: {}

}

fileTransfer.upload(’’, ‘’, options)
.then((data) => {
// success
}, (err) => {
// error
})
}


#2
uploadDocument(){
const fileTransfer: FileTransferObject = this.transfer.create();
let options: FileUploadOptions = {
//The name of the form element.(optional)
fileKey: ‘file’,

//The file name to use when saving the file on the server(optional)
fileName: ‘name.pdf’,  
headers: {}

}
fileTransfer.upload('url of your file', 'target url', options)
.then((data) => {
// success
}, (err) => {
// error
})
}

Hope this helps.


#3

hi thanks alot…i’m starting to understand it.
but how to put the target url if i need to use post method to upload doc on server: Before this I use the same api to upload picture and username. right now i have to use the same api to upload document as well.

PostDetail(form){

this.userDetail= {

Fullname: this.Fname,
UserPic: this.userPic
}

this.userInfoService.postDocumentAndPic(this.StatusId,this.userDetail).subscribe(data => {
console.log(“PostDetail”, data)
})
}


#4

:point_up: i use above method to post image. but don know how to use it o post document


#5

What type of document you want to send??


#6

pdf document and image


#7

Good… That can be done… so where are you getting stuck??