0

video file upload

def upload_video( video ):
    video_name = "%d&&%s%s" % (int(round(time.time() * 1000)), "uservideo", os.path.splitext( video.name )[1])
    image_path = '%s/%s' % (DATA_ROOT, video_name)
    full_path = '%s%s' % (BASE_DIR, image_path)
    try:
        with open(full_path,'wb') as fp:
            for chunk in video.chunks():
                fp.write(chunk)

        os.chmod( full_path, 0666 )

    except Exception as err:

    return image_path

I need thumbnail image on video file

def ajax_videoUpload( request ):
    video = request.FILES[request.FILES.keys()[0]]


    videoPath = upload_video( video )
    fullPath = "%s%s" % ( BASE_DIR, videoPath )
    fileExt = os.path.splitext( videoPath )[1] # file extension
    clip = VideoFileClip( fullPath )
    fullPath = string.replace( fullPath, fileExt, ".png" )
    clip.save_frame( fullPath, t = 10.00 )
    thumbnailPath = string.replace( videoPath, fileExt, ".png" )

    return HttpResponse( thumbnailPath )

videoFileClip( fullPath ) <-- given error

Traceback (most recent call last):
File "/opt/djangostack-1.8.3-0/apps/django/lib/python2.7/site-packages/Django-1.8.3-py2.7.egg/django/core/handlers/base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/djangostack-1.8.3-0/apps/django/lib/python2.7/site-packages/Django-1.8.3-py2.7.egg/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/opt/djangostack-1.8.3-0/apps/django/django_projects/tellpin/writingform/views.py", line 392, in ajax_videoUpload
clip = VideoFileClip( fullPath )
File "/opt/djangostack-1.8.3-0/python/lib/python2.7/site-packages/moviepy/video/io/VideoFileClip.py", line 55, in __init__
reader = FFMPEG_VideoReader(filename, pix_fmt=pix_fmt)
File "/opt/djangostack-1.8.3-0/python/lib/python2.7/site-packages/moviepy/video/io/ffmpeg_reader.py", line 32, in __init__
infos = ffmpeg_parse_infos(filename, print_infos, check_duration)
File "/opt/djangostack-1.8.3-0/python/lib/python2.7/site-packages/moviepy/video/io/ffmpeg_reader.py", line 237, in ffmpeg_parse_infos
proc = sp.Popen(cmd, **popen_params)
File "/opt/djangostack-1.8.3-0/python/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/opt/djangostack-1.8.3-0/python/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied

this code is good working in my local my local OS win7, python 2.7 but not working in server

i tried file permission, and directory permission

sorry , I'm korean, so i'm not good in english.....

server os centOS 6, python 2.7.9, django 1.7

장민석
  • 5
  • 4
  • your view function was defective – iraj jelodari Dec 04 '15 at 00:32
  • What is the question? What have you done so far to solve this? Tell us [what you've tried](http://whathaveyoutried.com), and where you are stuck. This will help us answer your question better. – Steve Clanton Dec 04 '15 at 00:32
  • I guess your webserver does not have sufficient permission. Checkout webserver's `uid/gid` and then do a `ls -l` to check the permission of the directory you're trying manipulate. Fixit using `chown` and `chmod`... – Aftnix Dec 04 '15 at 03:35

1 Answers1

0

If the user that the python script runs as does not have proper filesystem permissions for the action you are attempting, you cannot change the user permissions in your script.

Also your approach is flawed because you're trying to grant yourself write permission after writing the file. It has to happen in the reverse order to work around a permission denied error.

It sounds like this is the case but a little difficult to discern from your question.

I am answering from a cell phone so forgive the formatting.

Use chmod from the command line to give permissions to the user running your script.

Without more context I would guess this user to be the user that your web server uses to drop root privileges.

The reason your script works locally is you are running django s runsever for development and it runs as your user. The typical production configuration uses a webserver like nginx or apache which changes to a safe user.

user319862
  • 1,797
  • 2
  • 24
  • 32