Added better file handling.
This commit is contained in:
		
							parent
							
								
									c4e3f1fc1f
								
							
						
					
					
						commit
						c6c2766381
					
				@ -25,6 +25,7 @@ class UploadView(BaseView):
 | 
				
			|||||||
        drive_item = await self.services.drive_item.get(uid)
 | 
					        drive_item = await self.services.drive_item.get(uid)
 | 
				
			||||||
        response = web.FileResponse(drive_item["path"])
 | 
					        response = web.FileResponse(drive_item["path"])
 | 
				
			||||||
        response.headers['Cache-Control'] = f'public, max-age={1337*420}'
 | 
					        response.headers['Cache-Control'] = f'public, max-age={1337*420}'
 | 
				
			||||||
 | 
					        response.headers['Content-Disposition'] = f'attachment; filename="{drive_item["name"]}"'
 | 
				
			||||||
        return response
 | 
					        return response
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async def post(self):
 | 
					    async def post(self):
 | 
				
			||||||
@ -57,8 +58,10 @@ class UploadView(BaseView):
 | 
				
			|||||||
            filename = field.filename
 | 
					            filename = field.filename
 | 
				
			||||||
            if not filename:
 | 
					            if not filename:
 | 
				
			||||||
                continue
 | 
					                continue
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            name = str(uuid.uuid4()) + pathlib.Path(filename).suffix
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            file_path = pathlib.Path(UPLOAD_DIR).joinpath(filename.strip("/").strip("."))
 | 
					            file_path = pathlib.Path(UPLOAD_DIR).joinpath(name)
 | 
				
			||||||
            files.append(file_path)
 | 
					            files.append(file_path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            async with aiofiles.open(str(file_path.absolute()), 'wb') as f:
 | 
					            async with aiofiles.open(str(file_path.absolute()), 'wb') as f:
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user