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

  • SEARCH
  • Home
  • 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 7805125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:07:19+00:00 2026-06-02T02:07:19+00:00

def _tarFiles(filepaths): print create tar file from all files in file list and save

  • 0
def _tarFiles(filepaths):
print "create tar file from all files in file list and save to temp working dir. returns tarfile path "
try:
    savePathDir = settings.TAR_FILE_TARGET_DIRECTORY
    if not os.path.exists(savePathDir):
        os.makedirs(savePathDir)

    tarredfiles = tarfile.open(settings.TAR_FILE_TARGET_DIRECTORY + '/' + 'responsefiles.tar',mode='w')
    for f in filepaths:
        tarredfiles.add(f)

    tarredfiles.close()
    return ("Ok", settings.TAR_FILE_TARGET_DIRECTORY + '/' + 'responsefiles.tar')

except Exception as e:
    return ("Error in "+ inspect.stack()[0][3] + " " + e.message, None)

 def sendFiles(files):
    try:
        result, tarfilename = _tarFiles(files)
        if result == 'Ok':
            try:
                print tarfilename
                wrapper = FileWrapper(file(tarfilename))
                response = HttpResponse(wrapper, content_type='application/x-tar') #zip,avi,png,jpeg, etc...
                response['Content-Disposition'] = 'attachment; filename=' + tarfilename#tarredfiles.name #eg. myfile.zip
                response['Content-Length'] = str(os.path.getsize(tarfilename))
                return ("Ok",response)
            except Exception as e:
                return ("Error in "+ inspect.stack()[0][3] + " " + e.message, None)

        else:
            return (result,None)

    except Exception as e:
        return ("Error in "+ inspect.stack()[0][3] + " " +e.message,None)

tarfilename is the complete path to the file.
The content-length looks right (comparing actual file to getsize).

Works on a mac running runserver. Returns a partial file on windows running runserver. Or completely empty file if I step through on windows.

The target directory and filename generated is “tarred_files/responsefiles.tar”
the file size is 90K and the os.path.getsize returned is 92160

What am I doing that would cause an empty file to be downloaded?

  • 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-02T02:07:22+00:00Added an answer on June 2, 2026 at 2:07 am

    For windows, you need to add “rb” to file.

    like so:

    wrapper = FileWrapper(file(tarfilename,'rb'))
    

    Also, Content-Length should use a integer, not a string

    like so:

    response['Content-Length'] = os.path.getsize(tarfilename)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

def display_home(request): from datetime import * now=datetime.today() print 'Month is %s'%now.month events=Event.objects.filter(e_date__year=datetime.today().year).filter(e_date__month=datetime.today().month,e_status=1).values('e_name','e_date') return render_to_response("SecureVirtualElection/home.html",{'events':
def load_lib path = File.join(File.dirname(__FILE__), 'lib') failures = [] Dir.glob(#{path}/**/*.rb).each { |file| puts loading:
def process_dialect_translation_rules(): # Read in lines from the text file specified in sys.argv[1], stripping
def update @album = Album.find(params[:id]) if @album.update_attributes(params[:album]) redirect_to(:action=>'list') else render(:action=>'edit') end end A Rails
def foo(**args): for k, v in args.items(): print type(k), type(v) for k, v in
def myFunc(arg1, arg2): print This is a test with + arg1 + and +
def sortProfiles(p): return sorted(p, key=itemgetter('first_name')) I have a list with dictionaries. This function allows
def myFunc( str ): print str=, str if str == None: print str is
def makecounter(): return collections.defaultdict(int) class RankedIndex(object): def __init__(self): self._inverted_index = collections.defaultdict(list) self._documents = []
def self.source_root File.join(File.dirname(__FILE__), 'templates') end

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.