Created
May 14, 2020 18:04
-
-
Save TechRova/f0c4fa29ddcab30d1511c90446036933 to your computer and use it in GitHub Desktop.
Upload Service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import * as AWS from 'aws-sdk/global'; | |
import * as S3 from 'aws-sdk/clients/s3'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export default class UploadService { | |
constructor() { } | |
uploadFile(file) { | |
const contentType = file.type; | |
const bucket = new S3( | |
{ | |
accessKeyId: '0026b6bf5a8a9e50000000002', | |
secretAccessKey: 'K002iWYW42XJhvmH6hetBZe10L7ZbUM', | |
region: '', | |
endpoint: "https://s3.us-west-002.backblazeb2.com", | |
s3ForcePathStyle: true | |
} | |
); | |
const params = { | |
Bucket: 'videostream-s3', | |
Key: file.name, | |
Body: file, | |
ACL: 'public-read', | |
ContentType: contentType, | |
endpoint: "https://s3.us-west-002.backblazeb2.com", | |
s3ForcePathStyle: true | |
}; | |
bucket.upload(params).on('httpUploadProgress', (evt) => { | |
console.log(evt.loaded + ' of ' + evt.total + ' Bytes'); | |
}).send((err, data) => { | |
if (err) { | |
console.log('There was an error uploading your file: ', err); | |
return false; | |
} | |
console.log('Successfully uploaded file.', data); | |
return true; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment