Mercurial > libervia-backend
comparison sat/plugins/plugin_comp_file_sharing.py @ 3297:91b5ae058c66
comp file sharing: handle upload with headers:
`Xmpp-File-Path` can now be used to specify file path, and `Xmpp-File-No-Http` when file
must not be served publicly by HTTP.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 09 Jun 2020 06:23:01 +0200 |
parents | da443cf946ad |
children | 9d1c0feba048 |
comparison
equal
deleted
inserted
replaced
3296:da443cf946ad | 3297:91b5ae058c66 |
---|---|
190 # we close the content here, before registering the file | 190 # we close the content here, before registering the file |
191 request.content.close() | 191 request.content.close() |
192 tmp_file_path = Path(request.content.name) | 192 tmp_file_path = Path(request.content.name) |
193 request.content = None | 193 request.content = None |
194 | 194 |
195 # the 2 following headers are not standard, but useful in the context of file | |
196 # sharing with HTTP Upload: first one allow uploaded to specify the path | |
197 # and second one will disable public exposure of the file through HTTP | |
198 path = request.getHeader("Xmpp-File-Path") or "/uploads" | |
199 if request.getHeader("Xmpp-File-No-Http") is not None: | |
200 public_id = None | |
201 else: | |
202 public_id = upload_id | |
203 | |
195 file_data = { | 204 file_data = { |
196 "name": unquote(upload_request.filename), | 205 "name": unquote(upload_request.filename), |
197 "mime_type": upload_request.content_type, | 206 "mime_type": upload_request.content_type, |
198 "size": upload_request.size, | 207 "size": upload_request.size, |
199 "path": "/uploads" | 208 "path": path |
200 } | 209 } |
201 | 210 |
202 await request.file_sharing.registerReceivedFile( | 211 await request.file_sharing.registerReceivedFile( |
203 client, upload_request.from_, file_data, tmp_file_path, | 212 client, upload_request.from_, file_data, tmp_file_path, |
204 public_id=upload_id, | 213 public_id=public_id, |
205 ) | 214 ) |
206 | 215 |
207 request.setResponseCode(http.CREATED) | 216 request.setResponseCode(http.CREATED) |
208 request.finish() | 217 request.finish() |
209 | 218 |