2017-06-28 12 views
0

私は曇っていて、Angular4です。Angular4からCloudinalへの画像をアップロード

私は、Angular4経由で画像をCloudNodeにアップロードする方法を探していましたが、そのドキュメントを見つけることができませんでした。私が見つけたドキュメントは、アップロードするのではなくイメージの変換に関係しています。

Angular4から画像を雲にアップロードするにはどうすればよいですか?

PS。私はAngular4 AOTを使用しています

答えて

0

hereがあります。 Angular4でもうまく動作するng2-file-uploadを使用しています。考慮すべき

主なポイントは、あなたのCloudinaryアカウントへwiring the uploaderある -

// Create the file uploader, wire it to upload to your account 
const uploaderOptions: FileUploaderOptions = { 
    url: `https://api.cloudinary.com/v1_1/${this.cloudinary.config().cloud_name}/upload`, 
    // Upload files automatically upon addition to upload queue 
    autoUpload: true, 
    // Use xhrTransport in favor of iframeTransport 
    isHTML5: true, 
    // Calculate progress independently for each uploaded file 
    removeAfterUpload: true, 
    // XHR request headers 
    headers: [ 
    { 
     name: 'X-Requested-With', 
     value: 'XMLHttpRequest' 
    } 
    ] 
}; 
this.uploader = new FileUploader(uploaderOptions); 

this.uploader.onBuildItemForm = (fileItem: any, form: FormData): any => { 
    // Add Cloudinary's unsigned upload preset to the upload form 
    form.append('upload_preset', this.cloudinary.config().upload_preset); 
    // Add built-in and custom tags for displaying the uploaded photo in the list 
    let tags = 'myphotoalbum'; 
    if (this.title) { 
    form.append('context', `photo=${this.title}`); 
    tags = `myphotoalbum,${this.title}`; 
    } 
    form.append('tags', tags); 
    form.append('file', fileItem); 

    // Use default "withCredentials" value for CORS requests 
    fileItem.withCredentials = false; 
    return { fileItem, form }; 
}; 
関連する問題