Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7827863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:04:26+00:00 2026-06-02T10:04:26+00:00

Currently I am saving a file to a loal directory from a ftp server.

  • 0

Currently I am saving a file to a loal directory from a ftp server. But I want to move to using ImageFields to make things more manageable.

here is the current code snippet

file_handle = open(savePathDir +'/' +  fname, "wb")            
nvcftp.retrbinary("RETR " + fname, _download_cb)
file_handle.close()    
return savePathDir +'/' +  fname

Here is my first attempt at matching. I am returning the path just for compatibilities sake for now. Later I will access the stored files properly through the model.

new_image = CameraImage(video_channel = videochannel,timestamp = file_timestamp)
file_handle = new_image.image.open()
nvcftp.retrbinary("RETR " + fname, _download_cb)
file_handle.close()
new_image.save()
return new_image.path()

Is this correct?
I am confused about what order I should deal with the file_handle and the ImageField “image”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:04:29+00:00Added an answer on June 2, 2026 at 10:04 am

    You are missing _download_cb, so I’m not using it.
    Refs The File Object of Django. Try

    # retrieve file from ftp to memory,
    # consider using cStringIO or tempfile modules for your actual usage
    
    from StringIO import StringIO
    from django.core.files.base import ContentFile
    s = StringIO()
    nvcftp.retrbinary("RETR " + fname, s.write)
    s.seek(0)  
    # feed the fetched file to Django image field
    new_image.image.save(fname, ContentFile(s.read()))
    s.close()
    
    # Or
    from django.core.files.base import File
    s = StringIO()
    nvcftp.retrbinary("RETR " + fname, s.write)
    s.size = s.tell()
    new_image.image.save(fname, File(s))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently saving a message to a single file from multiple activity classes
I'm using EntLib v4 for Logging and currently I'm saving the events to the
From my experience this is what i come up with. Im currently saving Users
Im currently trying to move my site from localhost on my machine to my
I'm currently saving an NSDictionary to file on the iOS device. However, NSDictionary files
I'm currently working with some code involving saving a file to a user-defined file.
From PHP I am used to just saving the .php file and reloading the
In an iPhone app I currently have code for downloading a file from the
Currently we are saving all SOAP requests to a log file (rolling, one per
Currently we are saving files (PDF, DOC) into the database as BLOB fields. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.