Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cloud api services #33

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions src/AWSStorageService.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,40 @@ export class AWSStorageService extends BaseStorageService {
'result': result
}
}
upload(container, fileName, filePath, callback) {
throw new Error('BaseStorageService :: upload() must be implemented');
}

/**
* @upload
* @description - Uplaod file directly to AWS storage
* @param { string } container - bucket name
* @param { string } fileName - Path to the file in the bucket.
* @param { Buffer } fileContent - file data which needs to uploaded
* @return { Promise<string> } - A signed URL for the specified operation on the file.
*/

async upload(container, fileName, fileContent) {
return new Promise((resolve, reject) => {

let params = {
Bucket: container,
Key: fileName,
Body: fileContent,
};

const fileUpload = new Upload({
client: this.client,
params: params,
leavePartsOnError: false,
});

fileUpload.done()
.then((data) => {
resolve(data.Location);
})
.catch((error) => {
reject(error);
});
});
}

/**
* @description - Generates a signed URL for performing specified operations on a file in the AWS bucket.
Expand Down
26 changes: 24 additions & 2 deletions src/AzureStorageService.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,30 @@ export class AzureStorageService extends BaseStorageService {
}
}

upload(container, fileName, filePath, callback) {
throw new Error('AzureStorageService :: upload() must be implemented');
/**

* @description - Uplaod file directly to azure storage
* @upload
* @param { string } container - bucket name
* @param { string } fileName - Path to the file in the bucket.
* @param { Buffer } fileContent - file data which needs to uploaded
* @return { Promise<string>} } - Response Status code
*/

async upload(container, fileName, fileContent) {
return new Promise(async (resolve, reject) => {
let blobClient = this.blobService.getContainerClient(container).getBlockBlobClient(fileName);
try{
let fileUpload= await blobClient.upload(
fileContent,
fileContent.length,
);
resolve(fileUpload._response.status)
}catch(err){
reject(err);
}
})

}

/**
Expand Down
27 changes: 25 additions & 2 deletions src/GCPStorageService.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,31 @@ export class GCPStorageService extends BaseStorageService {
'result': result
}
}
upload(container, fileName, filePath, callback) {
throw new Error('BaseStorageService :: upload() must be implemented');

/**
* @upload
* @description - Uplaod file directly to GCP storage
* @param { string } container - bucket name
* @param { string } fileName - Path to the file in the bucket.
* @param { Buffer } fileContent - file data which needs to uploaded
* @return { Promise<string>} } - Response Success message.
*/
async upload(container, fileName, fileContent) {
return new Promise((resolve, reject) => {

const fileUpload = this._storage.bucket(container).file(fileName);

fileUpload.save(fileContent, {
contentType: "application/octet-stream"
}, (err) => {
if (err) {
reject("error",err);
}
else {
resolve(`File saved successfully`);
}
});
})
}

/**
Expand Down
38 changes: 35 additions & 3 deletions src/OCIStorageService.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,41 @@ export class OCIStorageService extends BaseStorageService {
'result': result
}
}
upload(container, fileName, filePath, callback) {
throw new Error('OCIStorageService :: upload() must be implemented');
}

/**
* @upload
* @description - Uplaod file directly to OCI storage
* @param { string } container - bucket name
* @param { string } fileName - Path to the file in the bucket.
* @param { Buffer } fileContent - file data which needs to uploaded
* @return { Promise<string> } - A signed URL for the specified operation on the file.
*/

upload(container, fileName, fileContent, ) {

return new Promise((resolve, reject) => {

let params = {
Bucket: container,
Key: fileName,
Body: fileContent,
};

const fileUpload = new Upload({
client: this.client,
params: params,
leavePartsOnError: false,
});

fileUpload.done()
.then((data) => {
resolve(data.Location);
})
.catch((error) => {
reject(error);
});
});
}

/**
* @description - Generates a signed URL for performing specified operations on a file in the OCI bucket.
Expand Down