Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BlobApi
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Coscine
backend
apis
BlobApi
Commits
dd384bcb
Commit
dd384bcb
authored
4 years ago
by
Benedikt Heinrichs
Committed by
Marcel Nellesen
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
New: Implement GetUploadUrl & GetDownloadUrl
parent
4ab0d857
No related branches found
No related tags found
3 merge requests
!32
Product/1440 larger files
,
!31
Sprint/2021 07
,
!30
New: Implement GetUploadUrl & GetDownloadUrl
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Blob/Controllers/BlobController.cs
+67
-0
67 additions, 0 deletions
src/Blob/Controllers/BlobController.cs
with
67 additions
and
0 deletions
src/Blob/Controllers/BlobController.cs
+
67
−
0
View file @
dd384bcb
...
...
@@ -180,6 +180,73 @@ namespace Coscine.Api.Blob.Controllers
}
}
/// <summary>
/// This method returns the download url for a resource and path
/// </summary>
/// <param name="resourceId">Id of the resource</param>
/// <param name="path">Path to the to downloaded file</param>
/// <returns>Uri of the download url in the form of: "{ data: { url: url } }"</returns>
[
HttpGet
(
"[controller]/downloadUrl/{resourceId}/{*path}"
)]
public
async
Task
<
IActionResult
>
GetDownloadUrl
(
string
resourceId
,
string
path
)
{
return
await
GetUrl
(
resourceId
,
path
,
(
resourceTypeDefinition
,
path
,
version
,
resourceTypeOptions
)
=>
resourceTypeDefinition
.
GetEntryDownloadUrl
(
path
,
version
,
resourceTypeOptions
));
}
/// <summary>
/// This method returns the upload url for a resource and path
/// </summary>
/// <param name="resourceId">Id of the resource</param>
/// <param name="path">Path to the to uploaded file</param>
/// <returns>Uri of the upload url in the form of: "{ data: { url: url } }"</returns>
[
HttpGet
(
"[controller]/uploadUrl/{resourceId}/{*path}"
)]
public
async
Task
<
IActionResult
>
GetUploadUrl
(
string
resourceId
,
string
path
)
{
return
await
GetUrl
(
resourceId
,
path
,
(
resourceTypeDefinition
,
path
,
version
,
resourceTypeOptions
)
=>
resourceTypeDefinition
.
GetEntryStoreUrl
(
path
,
version
,
resourceTypeOptions
));
}
private
async
Task
<
IActionResult
>
GetUrl
(
string
resourceId
,
string
path
,
Func
<
ResourceTypeDefinition
,
string
,
string
,
Dictionary
<
string
,
string
>,
Task
<
Uri
>>
receiver
)
{
var
rawPath
=
path
;
var
user
=
_authenticator
.
GetUser
();
path
=
$"/
{
path
}
"
;
var
checkPath
=
CheckPath
(
path
);
if
(
checkPath
!=
null
)
{
return
checkPath
;
}
var
checkResourceId
=
CheckResource
(
resourceId
,
out
Resource
resource
);
if
(
checkResourceId
!=
null
)
{
return
checkResourceId
;
}
var
checkUser
=
CheckUser
(
user
,
resource
);
if
(
checkUser
!=
null
)
{
return
checkUser
;
}
var
resourceTypeOptions
=
_resourceModel
.
GetResourceTypeOptions
(
resource
.
Id
);
var
resourceTypeDefinition
=
ResourceTypeFactory
.
CreateResourceTypeObject
(
resource
.
Type
.
DisplayName
,
_configuration
);
if
(
resourceTypeDefinition
==
null
)
{
return
BadRequest
(
$"No provider for: \"
{
resource
.
Type
.
DisplayName
}
\"."
);
}
var
entryUrl
=
await
receiver
(
resourceTypeDefinition
,
rawPath
,
null
,
resourceTypeOptions
);
if
(
entryUrl
==
null
)
{
var
hostUrl
=
await
_configuration
.
GetStringAsync
(
"coscine/local/api/additional/url"
);
var
apiPath
=
$"/coscine/api/
{((
System
.
Reflection
.
Assembly
.
GetEntryAssembly
()
!=
null
)
?
System
.
Reflection
.
Assembly
.
GetEntryAssembly
().
GetName
().
Name
:
System
.
Reflection
.
Assembly
.
GetExecutingAssembly
().
GetName
().
Name
)}
"
;
entryUrl
=
new
Uri
(
$"
{
hostUrl
}{
apiPath
}
/Blob/
{
resourceId
}
/
{
rawPath
}
"
);
}
return
Ok
(
$"
{{
\
"data\": {{ \"url\": \"{entryUrl}\" }} }}"
);
}
/// <summary>
/// This method uploads a given File
/// </summary>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment