@@ -56,19 +56,16 @@ pub async fn upload_handler(
5656
5757 std:: fs:: create_dir_all ( & appstate. config . uploads_path ) ?;
5858
59- let is_s3 = appstate. config . opts . s3_bucket . is_some ( ) ;
60- let file_store = if is_s3 { "s3" } else { "fs" } ;
61- let file_id = format ! (
62- "{}-{}-{}" ,
63- file_store,
59+ let fs_file_id = format ! (
60+ "{}-{}" ,
6461 now( ) ,
6562 sanitize_filename:: sanitize( filename)
6663 // Spacebars lead to very annoying bugs in browsers
6764 . replace( ' ' , "-" )
6865 ) ;
6966
7067 let mut file_path = appstate. config . uploads_path . clone ( ) ;
71- file_path. push ( & file_id ) ;
68+ file_path. push ( & fs_file_id ) ;
7269 let mut file = File :: create ( & file_path) ?;
7370
7471 // Field in turn is stream of *Bytes* object
@@ -84,6 +81,9 @@ pub async fn upload_handler(
8481 . try_into ( )
8582 . map_err ( |_e| "Too large" ) ?;
8683
84+ let is_s3 = appstate. config . opts . s3_bucket . is_some ( ) ;
85+ let file_store = if is_s3 { "s3" } else { "fs" } ;
86+ let file_id = format ! ( "{}:{}" , & file_store, & fs_file_id) ;
8787 if is_s3 {
8888 upload_object ( & appstate, & file_id, & file_path) . await ?;
8989 fs:: remove_file ( & file_path) ?;
@@ -176,16 +176,3 @@ async fn upload_object(
176176
177177 Ok ( ( ) )
178178}
179-
180- #[ cfg( test) ]
181- mod tests {
182- use super :: * ;
183-
184- #[ actix_web:: test]
185- async fn upload_object_works ( ) {
186- let mut file = File :: create ( & "/tmp/test" ) . unwrap ( ) ;
187- file. write_all ( "it works!" . as_bytes ( ) ) . unwrap ( ) ;
188- let _ = upload_object ( & "it-works" , file) . await ;
189- assert ! ( true ) ;
190- }
191- }
0 commit comments