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

Upadte All Projects to use Amazon services #1

Merged
merged 8 commits into from
May 16, 2024
Merged
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
67 changes: 41 additions & 26 deletions ASP.NET Core/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
@using ASP_NET_Core.Models
<script src="~/services/azure.gateway.js"></script>
<script type="text/javascript" src="~/services/amazon.filesystem.js"></script>
<script type="text/javascript" src="~/services/amazon.gateway.js"></script>

<div id="wrapper">
<div id="widget-area">
@(Html.DevExtreme().FileUploader()
.ID("file-uploader")
.ChunkSize(200000)
.MaxFileSize(1048576)
.ChunkSize(5242880)
.UploadChunk("uploadChunk")
.OnValueChanged("onValueChanged")
.OnUploaded("onUploaded")
)
<div id="download-panel"></div>
<div id="request-panel"></div>
</div>
@(Html.DevExtreme().LoadPanel()
.ID("load-panel")
.Visible(true)
.Position(p => p.Of("#file-uploader"))
.Position(p => p.Of("#widget-area"))
)
<div id="message-box">
To run the demo locally, specify your Azure storage account name, access key and container name in the appsettings.json file in your back-end app.
To run the demo locally, specify your Amazon access key, secret key, region and bucket name in the appsettings.json file in your back-end app.
</div>
</div>

<script>
$.ajax({
url: 'https://localhost:7021/api/file-azure-status?widgetType=fileUploader',
url: 'https://localhost:52366/api/AmazonS3/getItems',
success(result) {
result.active = true;
const className = result.active ? 'show-widget' : 'show-message';
$('#wrapper').addClass(className);
$("#load-panel").dxLoadPanel("hide");
Expand All @@ -34,24 +38,35 @@
}
});

function uploadChunk(file, uploadInfo) {
let promise = null;
if (uploadInfo.chunkIndex === 0) {
promise = gateway.getUploadAccessUrl(file.name).then(function (accessUrls) {
uploadInfo.customData.accessUrl = accessUrls.url1;
});
} else {
promise = Promise.resolve();
}
promise = promise.then(function () {
return gateway.putBlock(uploadInfo.customData.accessUrl, uploadInfo.chunkIndex, uploadInfo.chunkBlob);
});
if (uploadInfo.chunkIndex === uploadInfo.chunkCount - 1) {
promise = promise.then(function () {
return gateway.putBlockList(uploadInfo.customData.accessUrl, uploadInfo.chunkCount);
});
}
return promise;

const onUploaded = async function(e) {
const url = await amazon.getPresignedDownloadUrl(e.file.name);
showPresignedUrl(url, e.file.name);
}

function onValueChanged(e) {
hidePresignedUrl();
}

async function uploadChunk(file, uploadInfo) {
return await amazon.uploadFileChunk(file, uploadInfo);
};

function showPresignedUrl(url, fileName) {
$('<div>')
.attr('id', 'url-div')
.append(
$('<span>').text('Download uploaded file: '),
$('<a>')
.attr('href', url)
.attr('target', '_blank')
.text(fileName)
)
.appendTo('#download-panel');
}

function hidePresignedUrl() {
$('#url-div').remove();
}

function onRequestExecuted(e) {
Expand All @@ -71,6 +86,6 @@
);
}

const endpointUrl = 'https://localhost:7021/api/file-uploader-azure-access';
const gateway = new AzureGateway(endpointUrl, onRequestExecuted);
const endpointUrl = 'https://localhost:52366/api/AmazonS3';
const amazon = new AmazonFileSystem(endpointUrl, onRequestExecuted);
</script>
11 changes: 11 additions & 0 deletions ASP.NET Core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ASP.NET Core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"dependencies": {
"jquery": "3.5.1",
"file-saver":"2.0.5",
"devextreme-dist": "^23.1.3",
"devextreme-aspnet-data": "^2.9.1",
"bootstrap": "^4.6.0"
Expand Down
Loading
Loading