Upload, process and then download a file in Django











up vote
0
down vote

favorite












I am making a Django app where one uploads a .mp3, then this .mp3 file is processed by the server, and then the user can download the processed file.



I don't know how to handle the uploads and downloads. I have tried using filetransfers but it doesn't seem to answer my problem.



PS : I am not at all familiarized with Http protocols...










share|improve this question






















  • Possible duplicate of Need a minimal Django file upload example
    – joppich
    Nov 19 at 15:54










  • While filetransfers most definetly fulfills your requirements, it might be a bit 'too much' for your usecase. But the django-doc on uploads is basically a guide to doing exactly what you want to do.
    – joppich
    Nov 19 at 15:58















up vote
0
down vote

favorite












I am making a Django app where one uploads a .mp3, then this .mp3 file is processed by the server, and then the user can download the processed file.



I don't know how to handle the uploads and downloads. I have tried using filetransfers but it doesn't seem to answer my problem.



PS : I am not at all familiarized with Http protocols...










share|improve this question






















  • Possible duplicate of Need a minimal Django file upload example
    – joppich
    Nov 19 at 15:54










  • While filetransfers most definetly fulfills your requirements, it might be a bit 'too much' for your usecase. But the django-doc on uploads is basically a guide to doing exactly what you want to do.
    – joppich
    Nov 19 at 15:58













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am making a Django app where one uploads a .mp3, then this .mp3 file is processed by the server, and then the user can download the processed file.



I don't know how to handle the uploads and downloads. I have tried using filetransfers but it doesn't seem to answer my problem.



PS : I am not at all familiarized with Http protocols...










share|improve this question













I am making a Django app where one uploads a .mp3, then this .mp3 file is processed by the server, and then the user can download the processed file.



I don't know how to handle the uploads and downloads. I have tried using filetransfers but it doesn't seem to answer my problem.



PS : I am not at all familiarized with Http protocols...







django






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 15:41









tk_slo

31




31












  • Possible duplicate of Need a minimal Django file upload example
    – joppich
    Nov 19 at 15:54










  • While filetransfers most definetly fulfills your requirements, it might be a bit 'too much' for your usecase. But the django-doc on uploads is basically a guide to doing exactly what you want to do.
    – joppich
    Nov 19 at 15:58


















  • Possible duplicate of Need a minimal Django file upload example
    – joppich
    Nov 19 at 15:54










  • While filetransfers most definetly fulfills your requirements, it might be a bit 'too much' for your usecase. But the django-doc on uploads is basically a guide to doing exactly what you want to do.
    – joppich
    Nov 19 at 15:58
















Possible duplicate of Need a minimal Django file upload example
– joppich
Nov 19 at 15:54




Possible duplicate of Need a minimal Django file upload example
– joppich
Nov 19 at 15:54












While filetransfers most definetly fulfills your requirements, it might be a bit 'too much' for your usecase. But the django-doc on uploads is basically a guide to doing exactly what you want to do.
– joppich
Nov 19 at 15:58




While filetransfers most definetly fulfills your requirements, it might be a bit 'too much' for your usecase. But the django-doc on uploads is basically a guide to doing exactly what you want to do.
– joppich
Nov 19 at 15:58












1 Answer
1






active

oldest

votes

















up vote
0
down vote













To load the files, the FileField class is used.



FileField class (upload_to = None, max_length = 100, ** options)


The directory where the files are saved must be specified.



Example:



class MyModel(models.Model):
# file will be uploaded to MEDIA_ROOT/uploads
upload = models.FileField(upload_to='uploads/')
# or...
# file will be saved to MEDIA_ROOT/uploads/2015/01/30
upload = models.FileField(upload_to='uploads/%Y/%m/%d/')


You must also have configured the "settings.py" file with the file addresses.



STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')


Storage can also be done remotely, that is, have another storage server, be a server and make the connection through FTP or use another service such as AWS S3.



if used FTP:



DEFAULT_FILE_STORAGE = 'storages.backends.ftp.FTPStorage'
USER = 'userftp'
PASSWORD = "passftp"
HOST = 'ftp.host.com or IP'
PORT = 21
FTP_STORAGE_LOCATION = "ftp://{user}:{passwd}@{host}:{port}/".format(user=USER, passwd=PASSWORD, host=HOST, port=PORT)


if used S3



AWS_STORAGE_BUCKET_NAME = os.getenv('AWS_BUCKET_NAME')
AWS_ACCESS_KEY_ID = os.getenv('AWS_S3_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY_ID = os.getenv('AWS_S3_SECRET_KEY')
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
AWS_S3_OBJECT_PARAMETERS = { 'CacheControl': 'max-age=86400' }
AWS_LOCATION = 'static'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'code/static'),]
STATIC_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'


and in the "urls.py" file add:



urlpatterns = [
url(r'^admin/', admin.site.urls),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378100%2fupload-process-and-then-download-a-file-in-django%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    To load the files, the FileField class is used.



    FileField class (upload_to = None, max_length = 100, ** options)


    The directory where the files are saved must be specified.



    Example:



    class MyModel(models.Model):
    # file will be uploaded to MEDIA_ROOT/uploads
    upload = models.FileField(upload_to='uploads/')
    # or...
    # file will be saved to MEDIA_ROOT/uploads/2015/01/30
    upload = models.FileField(upload_to='uploads/%Y/%m/%d/')


    You must also have configured the "settings.py" file with the file addresses.



    STATIC_URL = '/static/'
    MEDIA_URL = '/media/'
    MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')


    Storage can also be done remotely, that is, have another storage server, be a server and make the connection through FTP or use another service such as AWS S3.



    if used FTP:



    DEFAULT_FILE_STORAGE = 'storages.backends.ftp.FTPStorage'
    USER = 'userftp'
    PASSWORD = "passftp"
    HOST = 'ftp.host.com or IP'
    PORT = 21
    FTP_STORAGE_LOCATION = "ftp://{user}:{passwd}@{host}:{port}/".format(user=USER, passwd=PASSWORD, host=HOST, port=PORT)


    if used S3



    AWS_STORAGE_BUCKET_NAME = os.getenv('AWS_BUCKET_NAME')
    AWS_ACCESS_KEY_ID = os.getenv('AWS_S3_ACCESS_KEY_ID')
    AWS_SECRET_ACCESS_KEY_ID = os.getenv('AWS_S3_SECRET_KEY')
    AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
    AWS_S3_OBJECT_PARAMETERS = { 'CacheControl': 'max-age=86400' }
    AWS_LOCATION = 'static'
    STATICFILES_DIRS = [os.path.join(BASE_DIR, 'code/static'),]
    STATIC_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
    STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'


    and in the "urls.py" file add:



    urlpatterns = [
    url(r'^admin/', admin.site.urls),
    ]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)





    share|improve this answer

























      up vote
      0
      down vote













      To load the files, the FileField class is used.



      FileField class (upload_to = None, max_length = 100, ** options)


      The directory where the files are saved must be specified.



      Example:



      class MyModel(models.Model):
      # file will be uploaded to MEDIA_ROOT/uploads
      upload = models.FileField(upload_to='uploads/')
      # or...
      # file will be saved to MEDIA_ROOT/uploads/2015/01/30
      upload = models.FileField(upload_to='uploads/%Y/%m/%d/')


      You must also have configured the "settings.py" file with the file addresses.



      STATIC_URL = '/static/'
      MEDIA_URL = '/media/'
      MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')


      Storage can also be done remotely, that is, have another storage server, be a server and make the connection through FTP or use another service such as AWS S3.



      if used FTP:



      DEFAULT_FILE_STORAGE = 'storages.backends.ftp.FTPStorage'
      USER = 'userftp'
      PASSWORD = "passftp"
      HOST = 'ftp.host.com or IP'
      PORT = 21
      FTP_STORAGE_LOCATION = "ftp://{user}:{passwd}@{host}:{port}/".format(user=USER, passwd=PASSWORD, host=HOST, port=PORT)


      if used S3



      AWS_STORAGE_BUCKET_NAME = os.getenv('AWS_BUCKET_NAME')
      AWS_ACCESS_KEY_ID = os.getenv('AWS_S3_ACCESS_KEY_ID')
      AWS_SECRET_ACCESS_KEY_ID = os.getenv('AWS_S3_SECRET_KEY')
      AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
      AWS_S3_OBJECT_PARAMETERS = { 'CacheControl': 'max-age=86400' }
      AWS_LOCATION = 'static'
      STATICFILES_DIRS = [os.path.join(BASE_DIR, 'code/static'),]
      STATIC_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
      STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'


      and in the "urls.py" file add:



      urlpatterns = [
      url(r'^admin/', admin.site.urls),
      ]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        To load the files, the FileField class is used.



        FileField class (upload_to = None, max_length = 100, ** options)


        The directory where the files are saved must be specified.



        Example:



        class MyModel(models.Model):
        # file will be uploaded to MEDIA_ROOT/uploads
        upload = models.FileField(upload_to='uploads/')
        # or...
        # file will be saved to MEDIA_ROOT/uploads/2015/01/30
        upload = models.FileField(upload_to='uploads/%Y/%m/%d/')


        You must also have configured the "settings.py" file with the file addresses.



        STATIC_URL = '/static/'
        MEDIA_URL = '/media/'
        MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')


        Storage can also be done remotely, that is, have another storage server, be a server and make the connection through FTP or use another service such as AWS S3.



        if used FTP:



        DEFAULT_FILE_STORAGE = 'storages.backends.ftp.FTPStorage'
        USER = 'userftp'
        PASSWORD = "passftp"
        HOST = 'ftp.host.com or IP'
        PORT = 21
        FTP_STORAGE_LOCATION = "ftp://{user}:{passwd}@{host}:{port}/".format(user=USER, passwd=PASSWORD, host=HOST, port=PORT)


        if used S3



        AWS_STORAGE_BUCKET_NAME = os.getenv('AWS_BUCKET_NAME')
        AWS_ACCESS_KEY_ID = os.getenv('AWS_S3_ACCESS_KEY_ID')
        AWS_SECRET_ACCESS_KEY_ID = os.getenv('AWS_S3_SECRET_KEY')
        AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
        AWS_S3_OBJECT_PARAMETERS = { 'CacheControl': 'max-age=86400' }
        AWS_LOCATION = 'static'
        STATICFILES_DIRS = [os.path.join(BASE_DIR, 'code/static'),]
        STATIC_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
        STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'


        and in the "urls.py" file add:



        urlpatterns = [
        url(r'^admin/', admin.site.urls),
        ]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)





        share|improve this answer












        To load the files, the FileField class is used.



        FileField class (upload_to = None, max_length = 100, ** options)


        The directory where the files are saved must be specified.



        Example:



        class MyModel(models.Model):
        # file will be uploaded to MEDIA_ROOT/uploads
        upload = models.FileField(upload_to='uploads/')
        # or...
        # file will be saved to MEDIA_ROOT/uploads/2015/01/30
        upload = models.FileField(upload_to='uploads/%Y/%m/%d/')


        You must also have configured the "settings.py" file with the file addresses.



        STATIC_URL = '/static/'
        MEDIA_URL = '/media/'
        MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')


        Storage can also be done remotely, that is, have another storage server, be a server and make the connection through FTP or use another service such as AWS S3.



        if used FTP:



        DEFAULT_FILE_STORAGE = 'storages.backends.ftp.FTPStorage'
        USER = 'userftp'
        PASSWORD = "passftp"
        HOST = 'ftp.host.com or IP'
        PORT = 21
        FTP_STORAGE_LOCATION = "ftp://{user}:{passwd}@{host}:{port}/".format(user=USER, passwd=PASSWORD, host=HOST, port=PORT)


        if used S3



        AWS_STORAGE_BUCKET_NAME = os.getenv('AWS_BUCKET_NAME')
        AWS_ACCESS_KEY_ID = os.getenv('AWS_S3_ACCESS_KEY_ID')
        AWS_SECRET_ACCESS_KEY_ID = os.getenv('AWS_S3_SECRET_KEY')
        AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
        AWS_S3_OBJECT_PARAMETERS = { 'CacheControl': 'max-age=86400' }
        AWS_LOCATION = 'static'
        STATICFILES_DIRS = [os.path.join(BASE_DIR, 'code/static'),]
        STATIC_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
        STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'


        and in the "urls.py" file add:



        urlpatterns = [
        url(r'^admin/', admin.site.urls),
        ]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 at 16:22









        Diego Asencio

        12




        12






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378100%2fupload-process-and-then-download-a-file-in-django%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?