简体   繁体   English

如何在AS3 Flash中将文件上传到Django?

[英]How can I upload files to django from within AS3 Flash?

I need to build a file uploader in AS3 that is capable of uploading files into an authenticated django view which contains a form with a file upload input. 我需要在AS3中构建一个文件上传器,该文件上传器能够将文件上传到经过身份验证的Django视图中,该视图包含带有文件上传输入的表单。

I have been working on this for an entire 7 days, all day. 我整整一天都在工作7天。

After much digging, I have discovered that Adobe, in their infinite wisdom has disabled cookie headers from being sent from flash. 经过大量挖掘,我发现Adobe以其无穷的智慧禁止了cookie标头从闪存发送。 By default, django only accepts sessionid's via cookie, so I added a custom middleware that allows authentication via a sessionid POST var. 默认情况下,django仅通过cookie接受sessionid,因此我添加了一个自定义中间件,该中间件允许通过sessionid POST var进行身份验证。 This has been tested, and is functional. 这已经过测试,并且可以正常工作。

However, I still cannot upload, even with the sessionid in the POST. 但是,即使使用POST中的sessionid,我仍然无法上传。 When I do attempt an upload, the bytes seem to go up, and then for some reason, the upload fails. 当我尝试上传时,字节似乎增加了,然后由于某种原因,上传失败。 Here is said response. 这就是回应。

flash says selectHandler: name=douchetop.png URL=http://dev.citizengroove.com/upload/
progressHandler: name=douchetop.png bytesLoaded=32768 bytesTotal=139082
progressHandler: name=douchetop.png bytesLoaded=65536 bytesTotal=139082
progressHandler: name=douchetop.png bytesLoaded=98304 bytesTotal=139082
progressHandler: name=douchetop.png bytesLoaded=131072 bytesTotal=139082
progressHandler: name=douchetop.png bytesLoaded=139082 bytesTotal=139082
httpResponseStatusHandler: [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=500]
httpStatusHandler: [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=500]
flash says: ioErrorHandler: Error #2038: File I/O Error. URL: http://dev.citizengroove.com/upload/

Please, please, please help me! 请,请,请帮助我!

I'm not sure what the problem is, but I might be able to give you some advice to help you work through this. 我不确定是什么问题,但是我可以为您提供一些建议,以帮助您解决此问题。

Have you tried uploading the file via curl? 您是否尝试过通过curl上传文件?

curl http://dev.citizengroove.com/upload/ -d <Post Data> -T douchetop.png

Then, based on what that hands back to you, you might be able to debug this easier assuming that the problem is within django and not flash. 然后,根据返回给您的内容,假设问题出在django中而不是闪烁,您也许可以更轻松地进行调试。 If nothing else you will know which half of this is having the problem. 如果没有其他原因,您将知道其中有一半有问题。

I'm also not sure what the problem is, but I hope I can fling some helpful details your way. 我也不确定问题出在哪里,但是我希望我能按照您的方式提供一些有用的细节。 From what I can figure, your sending the data, but cannot reconstruct it on Django's end. 据我所知,您正在发送数据,但无法在Django的末端重建它。

For HttpRequest.FILES , the Django docs say: "Note that FILES will only contain data if the request method was POST and the <form> that posted to the request had enctype="multipart/form-data". Otherwise, FILES will be a blank dictionary-like object." 对于HttpRequest.FILESDjango文档说:“请注意,只有在请求方法为POST并且发布到请求的<form>具有enctype =“ multipart / form-data的情况下,FILES才会包含数据。”否则,FILES将为一个空白的类似字典的对象。”

If your not posting the form with enctype="multipart/form-data" , you'll have to reconstruct the file from request.raw_post_data . 如果您未使用enctype="multipart/form-data"发布表单,则必须从request.raw_post_data重构文件。 This is explained by @theivviax here . 这由@theivviax 在这里解释。

He initially wrote this comment when using Pluploads , which does have support for a flash backend for uploading large files over HTTP. 他最初在使用Pluploads时写了此评论,它确实支持Flash后端,用于通过HTTP上传大文件。 It's licensed under GPLv2, perhaps you can take a peek at their docs or sources. 它是根据GPLv2许可的,也许您可​​以看看他们的文档或来源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将文件上传到Django数据库 - How can I upload files into django database 如何使用Django Tinymce-filbrowser上传媒体文件? - How can I upload media files with Django Tinymce-filbrowser? 如何将多个文件上传到 Django model? - How can I upload multiple files in to a Django model? 我如何在Django Admin上注册用于上传文件的字段 - How i can register on Django admin a field for upload of files 如何使用graphene-django上传和下载文件? - How can I upload and download files with graphene-django? 如何从Django管理员上传多个文件? - How to upload multiple files from the Django admin? Django如何异步上传文件? 我可以为此目的使用 Celery 吗? 我将 django 表单传递给任务,但没有成功 - How can I upload files asynchronously in Django? Can I use Celery for this purpose? I passed django form to the task and it didn't work 如何在Django中上传文件? - How to upload files in Django? 如何从 Django 迁移中发送信号? - How can I send signals from within Django migrations? 如何使用默认文件存储(S3)通过 Django FormTools 表单向导上传文件? - How can I use the Default File Storage(S3) to upload files with Django FormTools form wizard?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM