Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why does photo.file.name contain local path? #43

Open
zzm88 opened this issue Mar 8, 2017 · 0 comments
Open

why does photo.file.name contain local path? #43

zzm88 opened this issue Mar 8, 2017 · 0 comments

Comments

@zzm88
Copy link

zzm88 commented Mar 8, 2017

jfu - views.py
why after instance.save(), instance.name becomes sth like "C:/foo/bar.jpg" what if I need only "bar.jpg"? I tried to change it but after instance.save() it goes back again.

I need it to be a "bar.jpg" because I want to handle it with easythumb

@require_POST
def upload( request,topic_id = ''):
    if topic_id  == '':
        pass
    else:
        t = topic.objects.get(id = topic_id)
        if t.picture != None:
            return None

    # The assumption here is that jQuery File Upload
    # has been configured to send files one at a time.
    # If multiple files can be uploaded simulatenously,
    # 'file' may be a list of files.
    file = upload_receive( request )


    instance = Photo( file = file )
    
    instance.slug = os.path.basename(instance.file.name)
    instance.file.name = os.path.basename(instance.file.name)
    instance.save()


    try:
        t.picture = instance
        t.save()
    except:
        pass

    basename = os.path.basename( instance.file.path )

    file_dict = {
        'name' : basename,
        'size' : file.size,

        'url': settings.MEDIA_URL + basename,
        'thumbnailUrl': settings.MEDIA_URL + basename,

        # 'deleteUrl': reverse('jfu_delete', kwargs = { 'pk': instance.pk }),
        # 'deleteType': 'POST',
    }

    return UploadResponse( request, file_dict )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant