- Newest
- Most votes
- Most comments
Could these statements be returning an exception you are not catching?
formupload = FormUpload()
if formupload.validate_on_submit():
item_drop_down = formupload.pesquisa_instrumento.data #variable to folder_name
arquivo = formupload.arquivo.data #variable to file_name
if not arquivo:
flash('Arquivo não selecionado','alert-danger')
return render_template('partitura-incluir.html', formupload=formupload)
Or possibly the return statement? Sorry for the long delay.
Did you see this document? https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-uploading-files.html
I've coded in python how to upload files, and this is what I've used successfully:
upload_file_response = s3.upload_file(source, destination, key, ExtraArgs=extra_args, Callback=callback,
Config=config)
Source is the file with path, destination is the bucket, key is the key you want displayed in the bucket, the other parms are optional.
Display the results you get in upload_file_response. It might help you debug why you are getting an error. Also, you will need to catch exceptions.
You could probably do with just s3.exceptions.ClientError and botocore.exceptions.ClientError. Note: I use s3 instead of s3_client. Hope this helps.
Yes i do! I have no problems with uploads, I want the files that were uploaded to be able to load a valid url to view the text files. I've coded this way in python to upload files in subfolders.
@app.route('/partitura-incluir', methods=['POST', 'GET'])
@login_required
def partitura_incluir():
formupload = FormUpload()
if formupload.validate_on_submit():
item_drop_down = formupload.pesquisa_instrumento.data #variable to folder_name
arquivo = formupload.arquivo.data #variable to file_name
if not arquivo:
flash('Arquivo não selecionado','alert-danger')
return render_template('partitura-incluir.html', formupload=formupload)
try:
file = secure_filename(arquivo.filename)
arquivo.save(file)
s3_client = boto3.client('s3')
s3_client.upload_file(file, S3_BUCKET, item_drop_down + '/{}'.format(arquivo.filename))
flash(f'included {arquivo.filename} on subfolder {item_drop_down.capitalize()}', 'alert-success')
return redirect(url_for('pasta_consultar'))
except Exception as error:
print(error)
return render_template('partitura-incluir.html', formupload=formupload)
Relevant content
- Accepted Answerasked 7 months ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated 9 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
this sentence is a treaty if you have not selected any files. Sorry this code is portuguese.