Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
postFile(targetPathURL){
// new Transfer
const fileTransfer = new Transfer();
// URL
var urlTo = "https://api.graph.cool/file/v1/ciz5dctr01prd015261q0o8jd";
// File for Upload
var targetPath = targetPathURL;
// File name only
var extension = targetPath.split(".").pop();
var filepart = "image";
var filename = filepart + "." + extension;
var options = {
fileKey: "data",
fileName: filename,
chunkedMode: false,
public download(fileUrl: string, fileName: string): Observable {
const fileTransfer = new Transfer();
const uri = `https:${fileUrl}?filename=${encodeURI(fileName)}`;
const targetUri = `${window.cordova.file.externalDataDirectory}${fileName}`;
fileTransfer.onProgress((event) => {
// console.debug('download onProgress:', event.loaded, event.total);
});
return Observable
.create((observer: Observer) => {
fileTransfer.download(
uri,
targetUri)
.then((entry) => {
// console.debug('download complete: ' + entry.toURL());
// FileOpener.open(entry.toURL(), 'application/');
uploadPhoto(imageURI) {
let fileTransfer = new Transfer();
this.iframedoc = document.getElementById('ap3-iframe').contentWindow.document;
let iframewin = document.getElementById('ap3-iframe').contentWindow.window;
console.log('imageURI', imageURI);
let image = imageURI.substr(imageURI.lastIndexOf('/') + 1);
let name = image.split("?")[0];
let anumber = image.split("?")[1];
let ajaxurl = iframewin.apppCore.ajaxurl;
if ('Android' === Device.device.platform) {
image = anumber + '.jpg';
}
private downloadImage(imageUrl: string, localPath: string): Promise {
let transfer = new Transfer();
return transfer.download(imageUrl, localPath);
}
const uploadProgress = new Subject();
const result: IUploadResult = {
uploadResult$: undefined,
uploadProgress$: uploadProgress.asObservable(),
abort: undefined,
};
const options: FileUploadOptions = {
httpMethod: 'POST',
fileKey: fieldName,
headers: this.apiUploadHeaders,
};
const fileTransfer = new Transfer();
fileTransfer.onProgress((event) => {
const percent = Math.round((event.loaded / event.total) * 100);
uploadProgress.next(percent);
if (percent === 100) {
Observable
.interval(150)
.take(10)
.map(value => value * 10)
.subscribe(value => uploadProgress.next(value));
}
});
upload = (image: string) : void => {
let ft = new Transfer();
let filename = _.uniqueId() + ".jpg";
let options = {
fileKey: 'file',
fileName: filename,
mimeType: 'image/jpeg',
chunkedMode: false,
headers: {
'Content-Type' : undefined
},
params: {
fileName: filename
}
};
ft.onProgress(this.onProgress);
ft.upload(image, "http://services.dtaalbers.com/staging/pictures", options, false)
.then((result: any) => {