[API] Refactor: set upload endpoint to form-data and increase limit to 5gb per upload
This commit is contained in:
parent
98c5986dd5
commit
f191fc646e
|
@ -19,7 +19,7 @@ pub struct Upload<'r> {
|
|||
file: TempFile<'r>,
|
||||
}
|
||||
|
||||
#[post("/upload", data = "<upload>")]
|
||||
#[post("/upload", data = "<upload>", format = "multipart/form-data")]
|
||||
pub async fn upload_file(
|
||||
pool: &State<PgPool>,
|
||||
user: AuthenticatedUser,
|
||||
|
@ -41,7 +41,7 @@ pub async fn upload_file(
|
|||
let encrypted = encrypt_data(&buffer, key.as_bytes(), &nonce);
|
||||
|
||||
let file_id = Uuid::new_v4().to_string();
|
||||
let storage_path = format!("/data/{}", file_id);
|
||||
let storage_path = format!("./data/{}", file_id);
|
||||
|
||||
fs::write(&storage_path, &encrypted).await.ok();
|
||||
fs::write(format!("{}.nonce", &storage_path), &nonce).await.ok();
|
||||
|
|
|
@ -52,6 +52,7 @@ async fn main() -> Result<(), rocket::Error> {
|
|||
.merge(("limits", rocket::data::Limits::new()
|
||||
.limit("form", ByteUnit::Gigabyte(5)) // 5 GB
|
||||
.limit("file", ByteUnit::Gigabyte(1)) // 1 GB
|
||||
.limit("data-form", ByteUnit::Gigabyte(5)) // 5 GB for multipart/form-data
|
||||
));
|
||||
|
||||
|
||||
|
|
|
@ -141,11 +141,9 @@ class _MainPageState extends State<MainPage> {
|
|||
filename: file.name,
|
||||
),
|
||||
);
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Caricamento in corso...')),
|
||||
SnackBar(content: Text('Caricamento di ${file.name} in corso...')),
|
||||
);
|
||||
|
||||
final response = await request.send();
|
||||
|
||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||
|
@ -185,9 +183,7 @@ class _MainPageState extends State<MainPage> {
|
|||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
// Save the file to disk
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
// Mobile platforms
|
||||
await FileSaver.instance.saveFile(
|
||||
name: file.name,
|
||||
bytes: response.bodyBytes,
|
||||
|
|
Loading…
Reference in a new issue