Python Forum
flask app to save images locally when deployed on heroku not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
flask app to save images locally when deployed on heroku not working
#1
I have written an app https://images99acres.herokuapp.com/.

This app allow users to upload images, if i run this app locally this app uploads images and saves it to the path which i have designated,

but i uploaded this app on heroku and when someone uploads images it uploads images here https://images99acres.herokuapp.com/_upl...onment.jpg

"_uploads/photos/image.jpg"

Below is my code:

from flask import Flask, redirect, render_template, request, session, url_for
from flask_dropzone import Dropzone
from flask_uploads import UploadSet, configure_uploads, IMAGES, patch_request_class

import os

app = Flask(__name__)
dropzone = Dropzone(app)


app.config['SECRET_KEY'] = 'supersecretkeygoeshere'

# Dropzone settings
app.config['DROPZONE_UPLOAD_MULTIPLE'] = True
app.config['DROPZONE_ALLOWED_FILE_CUSTOM'] = True
app.config['DROPZONE_ALLOWED_FILE_TYPE'] = 'image/*'
app.config['DROPZONE_REDIRECT_VIEW'] = 'results'

# Uploads settings
app.config['UPLOADED_PHOTOS_DEST'] = os.getcwd() + '/uploads'

photos = UploadSet('photos', IMAGES)
configure_uploads(app, photos)
patch_request_class(app)  # set maximum file size, default is 16MB


@app.route('/', methods=['GET', 'POST'])
def index():

    # set session for image results
    if "file_urls" not in session:
        session['file_urls'] = []
    # list to hold our uploaded image urls
    file_urls = session['file_urls']

    # handle image upload from Dropszone
    if request.method == 'POST':
        file_obj = request.files
        for f in file_obj:
            file = request.files.get(f)

            # save the file with to our photos folder
            filename = photos.save(
                file,
                name=file.filename    
            )

            # append image urls
            file_urls.append(photos.url(filename))

        session['file_urls'] = file_urls
        return "uploading..."
    # return dropzone template on GET request    
    return render_template('index.html')


@app.route('/results')
def results():

    # redirect to home if no images to display
    if "file_urls" not in session or session['file_urls'] == []:
        return redirect(url_for('index'))

    # set the file_urls and remove the session variable
    file_urls = session['file_urls']
    session.pop('file_urls', None)

    return render_template('results.html', file_urls=file_urls)

if __name__=="__main__":
    app.run()

#app.run(debug=True)
hat should i do? how can i solve this?

my previous post was for deployment which got solved

User has been warned for this post. Reason: Creating new threads unnecessarily, Post in incorrect forum
Reply
#2
getcwd() try to get current working directory on heroku which return _.
Try without:
# Uploads settings
app.config['UPLOADED_PHOTOS_DEST'] = '/uploads'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Star Leapcell: The Python-Friendly Alternative to Heroku + Airtable Hybrid IssacChan 1 396 Feb-01-2024, 06:00 AM
Last Post: Athi
  Deployed Spider on Heroku: How do I email downloaded files? JaneTan 2 1,523 Mar-24-2022, 08:31 AM
Last Post: JaneTan
  Heroku Error H10 jamesaarr 1 1,979 Oct-21-2021, 03:43 PM
Last Post: jamesaarr
  Importing Postgres Heroku from AWS S3 Drone4four 0 1,776 May-27-2021, 01:09 PM
Last Post: Drone4four
  Django project deployed to Heroku: Postgres security Drone4four 0 1,912 Mar-26-2021, 10:17 AM
Last Post: Drone4four
Question Flask, send_from_directory not working : solved SpongeB0B 2 7,346 Jan-26-2021, 07:02 AM
Last Post: SpongeB0B
  My flask website not working properly Aggam 2 2,112 Nov-03-2020, 09:53 AM
Last Post: Aggam
  Retrieve images base64 encoded MongoDB and Flask Nuwan16 2 3,234 Oct-13-2020, 06:25 PM
Last Post: Nuwan16
  Flask Can't Save Screenshot to Postgres Db firebird 3 2,342 Sep-21-2020, 09:22 PM
Last Post: firebird
  Flask, Posgresql - Multiple requests are not working bmaganti 5 2,672 Feb-20-2020, 03:02 PM
Last Post: bmaganti

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020