fix: upload big file
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
[default]
|
||||
limits = { file = "200MB", files = "200MB" }
|
||||
limits = { file = "200MB" }
|
||||
|
||||
@@ -1,25 +1,22 @@
|
||||
use crate::api::{CurrentUser, JsonAPI};
|
||||
use rocket::form::Form;
|
||||
use chrono::offset::Local;
|
||||
use rocket::fs::TempFile;
|
||||
use rocket::serde::json::json;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
#[derive(FromForm)]
|
||||
pub struct Upload<'f> {
|
||||
file: TempFile<'f>,
|
||||
}
|
||||
|
||||
#[post("/upload", data = "<form>")]
|
||||
pub async fn ipfs_upload(user: CurrentUser, mut form: Form<Upload<'_>>) -> JsonAPI {
|
||||
#[post("/upload", data = "<file>")]
|
||||
pub async fn ipfs_upload(user: CurrentUser, mut file: TempFile<'_>) -> JsonAPI {
|
||||
let file_dir = Path::new("user_files").join(&user.namehash);
|
||||
fs::create_dir_all(&file_dir)?;
|
||||
let file = &mut form.file;
|
||||
// dbg!(&file);
|
||||
let filename = file.name().unwrap_or("file").to_string()
|
||||
+ "."
|
||||
+ &file.content_type().map_or("", |ct| ct.sub().as_str());
|
||||
let filename = format!(
|
||||
"{}-{}.{}",
|
||||
Local::now().timestamp(),
|
||||
&file.content_type().map_or("unknow", |ct| ct.top().as_str()),
|
||||
&file.content_type().map_or("file", |ct| ct.sub().as_str())
|
||||
);
|
||||
debug!("dir: {}", &file_dir.to_str().unwrap());
|
||||
file.persist_to(file_dir.join(&filename)).await?;
|
||||
// dbg!(&file_dir);
|
||||
|
||||
Reference in New Issue
Block a user