YUI Image Uploader - OK on Firefox/Mac but not elsewhere

7 views
Skip to first unread message

phoebebright

unread,
Feb 9, 2009, 5:39:21 PM2/9/09
to Django users
Have been trying to get a RTE plugin working that will allow upload of
images. The YUI verion is almost there but will not play well with
browsers.

The plugin from here http://allmybrain.com/2008/11/06/example-yui-image-upload-with-yui-260/
I modified to get Javascript to make an asynchronous call to this
function in the view:

def uploadimage(request):
try:
upload_full_path = settings.CONTENT_IMAGES

upload = request.FILES['image']
dest = open(os.path.join(upload_full_path, upload.name), 'wb+')

for chunk in upload.chunks():
dest.write(chunk)

dest.close()

result='{status:"UPLOADED",image_url:"%s%s"}' %
(settings.CONTENT_IMAGES_URL, upload.name)

return_data = HttpResponse(result,mimetype='Content-Type: text/
html')

except Exception, e:
return_data = HttpResponse("Error in uploading image")

return_data.flush()

return return_data

The plugin was written for turbon gears/php and there is a tg example
here:

http://allmybrain.com/2007/10/22/yui-image-uploader-example-with-turbogears/

Firefox/Mac works perfectly. Safari downloads the image instead. No
version on PC appears to do anything, (but only have Mac for local
testing.)
Have tried every possible permutation of the content-type, Content-
Type and text/html definitely is the way to go. Various threads on
python refer to the need to open the file for reading as rb to make
sure windows knows it is binary, but not sure how to do that as the
response data is already in memory.

In desperation I have also tried to implement image upload in TinyMCE
- can't get FileBrowser working on PC. and FCKeditor no modifiable
image upload that I could find. So I am back with YUI and hoping
someone can suggest something to try....

esatte...@wi.rr.com

unread,
Feb 10, 2009, 11:49:16 AM2/10/09
to Django users
I found the TinyMCE & filebrowser insanely easy to impliment. I would
say 9 out of the 10 issued I had was simply a matter of defining the
right paths.

I also found that creating a symlink for the admin media folder and
calling it 'media/' solved most of the path name issues. that way you
can leave most of the default paths in the settings.py file and it
just works out of the box.

On Feb 9, 4:39 pm, phoebebright <phoebebright...@gmail.com> wrote:
> Have been trying to get a RTE plugin working that will allow upload of
> images.  The YUI verion is almost there but will not play well with
> browsers.
>
> The plugin from herehttp://allmybrain.com/2008/11/06/example-yui-image-upload-with-yui-260/
> I modified to get Javascript to make an asynchronous call to this
> function in the view:
>
> def uploadimage(request):
>         try:
>                 upload_full_path = settings.CONTENT_IMAGES
>
>                 upload = request.FILES['image']
>                 dest = open(os.path.join(upload_full_path, upload.name), 'wb+')
>
>                 for chunk in upload.chunks():
>                         dest.write(chunk)
>
>                 dest.close()
>
>                 result='{status:"UPLOADED",image_url:"%s%s"}' %
> (settings.CONTENT_IMAGES_URL, upload.name)
>
>                 return_data = HttpResponse(result,mimetype='Content-Type: text/
> html')
>
>         except Exception, e:
>                 return_data = HttpResponse("Error in uploading image")
>
>         return_data.flush()
>
>         return return_data
>
> The plugin was written for turbon gears/php and there is a tg example
> here:
>
> http://allmybrain.com/2007/10/22/yui-image-uploader-example-with-turb...

phoebebright

unread,
Feb 10, 2009, 2:10:35 PM2/10/09
to Django users
I'm pretty sure I have all the paths correct because the TinyMCE/
Filebrowser works ok on firefox mac, just not on any other browser.
The only setting I changed was FILEBROWSER_URL_WWW = '/site_media/
uploads/'. At this stage I am trying to get the upload to happen in
PHP as I can get that to work, but it seems silly to have to do
that. I will use any solution so if yours is working on multiple
browsers, maybe I should give it another go. But not sure where to
start in fixing it!!!

Phoebe.

On Feb 10, 4:49 pm, "esatterwh...@wi.rr.com" <esatterwh...@wi.rr.com>
wrote:

phoebebright

unread,
Feb 11, 2009, 5:33:28 PM2/11/09
to Django users
You were right - all the paths were right except one. When the upload
dialog loads it looks for /media/tinymce_2/jscripts/tiny_mce/
tiny_mce_popup.js and I had tiny_mce installed straight off media.
Phew. All working on Mac, awaiting the news on PC.

Never got YUI working - it uploads the files ok but something about
the returning httpresponse is not being handled correctly by most
browsers. I know it is a django problem because the I can call the
same plugin with a php script to handle the upload and it works ok.
Tried to get some info using drlog middleware to output response
codes, but for some reason it is not called in this case. May return
to this problem when I am more experienced with django...



On Feb 10, 7:10 pm, phoebebright <phoebebright...@gmail.com> wrote:
> I'm pretty sure I have all the paths correct because the TinyMCE/
> Filebrowser works ok on firefox mac, just not on any other browser.
> The only setting I changed was FILEBROWSER_URL_WWW = '/site_media/
> uploads/'.  At this stage I am trying to get the upload to happen in
> PHP as I can get that to work, but it seems silly to have to do
> that.   I will use any solution so if yours is working on multiple
> browsers, maybe I should give it another go.  But not sure where to
> start in fixing it!!!
>
> Phoebe.
>
> On Feb 10, 4:49 pm, "esatterwh...@wi.rr.com" <esatterwh...@wi.rr.com>
> wrote:
>
> > I found the TinyMCE & filebrowser insanely easy to impliment. I would
> > say 9 out of the 10 issued I had was simply a matter of defining the
> > right paths.
>
> > I also found that creating a symlink for the admin media folder and
> > calling it 'media/' solved most of the path name issues. that way you
> > can leave most of the default paths in the settings.py file and it
> > just works out of the box.
>
> > On Feb 9, 4:39 pm, phoebebright <phoebebright...@gmail.com> wrote:
>
> > > Have been trying to get a RTE plugin working that will allow upload of
> > > images.  TheYUIverion is almost there but will not play well with
> > > image upload that I could find.  So I am back withYUIand hoping
Reply all
Reply to author
Forward
0 new messages