@@ -189,6 +189,26 @@ async fn exec_external_command<'a>(
189
189
) ) )
190
190
}
191
191
192
+ async fn read_file_bytes < ' a > (
193
+ path_str : & str ,
194
+ request : & ' a RequestInfo ,
195
+ ) -> Result < Vec < u8 > , anyhow:: Error > {
196
+ let path = std:: path:: Path :: new ( path_str) ;
197
+ // If the path is relative, it's relative to the web root, not the current working directory,
198
+ // and it can be fetched from the on-database filesystem table
199
+ if path. is_relative ( ) {
200
+ request
201
+ . app_state
202
+ . file_system
203
+ . read_file ( & request. app_state , path, true )
204
+ . await
205
+ } else {
206
+ tokio:: fs:: read ( path)
207
+ . await
208
+ . with_context ( || format ! ( "Unable to read file {path:?}" ) )
209
+ }
210
+ }
211
+
192
212
async fn read_file_as_text < ' a > (
193
213
param0 : & StmtParam ,
194
214
request : & ' a RequestInfo ,
@@ -197,9 +217,7 @@ async fn read_file_as_text<'a>(
197
217
log:: debug!( "read_file: first argument is NULL, returning NULL" ) ;
198
218
return Ok ( None ) ;
199
219
} ;
200
- let bytes = tokio:: fs:: read ( evaluated_param. as_ref ( ) )
201
- . await
202
- . with_context ( || format ! ( "Unable to read file {evaluated_param}" ) ) ?;
220
+ let bytes = read_file_bytes ( & evaluated_param, request) . await ?;
203
221
let as_str = String :: from_utf8 ( bytes)
204
222
. with_context ( || format ! ( "read_file_as_text: {param0:?} does not contain raw UTF8 text" ) ) ?;
205
223
Ok ( Some ( Cow :: Owned ( as_str) ) )
@@ -213,9 +231,7 @@ async fn read_file_as_data_url<'a>(
213
231
log:: debug!( "read_file: first argument is NULL, returning NULL" ) ;
214
232
return Ok ( None ) ;
215
233
} ;
216
- let bytes = tokio:: fs:: read ( evaluated_param. as_ref ( ) )
217
- . await
218
- . with_context ( || format ! ( "Unable to read file {evaluated_param}" ) ) ?;
234
+ let bytes = read_file_bytes ( & evaluated_param, request) . await ?;
219
235
let mime = mime_from_upload ( param0, request) . map_or_else (
220
236
|| Cow :: Owned ( mime_guess_from_filename ( & evaluated_param) ) ,
221
237
Cow :: Borrowed ,
0 commit comments