def get_file(): if request.method == 'GET': return redirect(url_for('upload')) elif request.method == 'POST': file = request.files["file"] file.save(os.path.join(UPLOAD_FOLDER, secure_filename(file.filename))) form = request.form new_file = 'temp/' + secure_filename(file.filename) print(new_file) if '.pdf' in new_file: try: file_id = uploadFile(new_file, form['Name']) new_pdffile = PDF(new_file) page_count = new_pdffile.get_page_count() front = 'https://drive.google.com/thumbnail?authuser=0&sz=w320&id=' + file_id print("successfully uploaded") mongoBook.post_book(file_id, form['Name'], form['Type'], form['Subject'], form['Author'], form['Description'], page_count, front) os.remove(new_file) return render_template('upload.html', display_navbar="inline", name=first_Name, picture=profile_pic, display_upload="block", uploadNoti="Successfully uploaded to AmongUSTH") except Exception as e: print(e) print('Cannot upload file!') return render_template('upload.html', display_navbar="inline", name=first_Name, picture=profile_pic, display_upload="block", uploadNoti="Upload failed! Please try again or contact us!")
def get_file(): if request.method == 'GET': return redirect(url_for('upload')) elif request.method == 'POST': file = request.files["file"] file.save(os.path.join(UPLOAD_FOLDER, secure_filename(file.filename))) form = request.form new_file = 'temp/' + secure_filename(file.filename) print(new_file) if '.pdf' in new_file: try: file_id = uploadFile(new_file, form['Name']) new_pdffile = PDF(new_file) page_count = new_pdffile.get_page_count() front = 'https://drive.google.com/thumbnail?authuser=0&sz=w320&id=' + file_id print("successfully uploaded") mongoBook.post_book(file_id, form['Name'], form['Type'], form['Subject'], form['Author'], form['Description'], page_count, front) except Exception: print (Exception) print('Cannot upload file!') return redirect(url_for('upload'))