Python 3.3瓶图像上传不返回

时间:2014-03-13 17:19:06

标签: python ajax bottle

我正在使用Python 3.3 with Bottle。

我的网页使用AJAX对我的Bottle网络服务进行跨域调用。有问题的路线是/ imageSave。它在POST调用中传递图像而不仅仅是文本。路线被击中并保存了图像,但由于一些奇怪的原因,它没有返回该字符串。

所有其他路由都能正常工作并返回正确的JSONP格式内容,因此我不确定此功能的不同之处。

故障路线:

    @post('/imageSave')
    def imageSave():
        response.content_type = "application/json"
        callback = request.query.callback
        upload = request.files.get('fileInput')
        returnJson = {}

        if upload is not None:
            name, ext = os.path.splitext(upload.filename)

            if ext not in ('.png','.jpg','.jpeg'):
                print("File extension not allowed.")

            save_path = "C:/uploads"
            if not os.path.exists(save_path):
                os.makedirs(save_path)
            dynFileName = "Img_"+str(strftime("%Y.%m.%d.%H.%M.%S", gmtime()))+str(ext)
            file_path = "{path}/{file}".format(path=save_path, file=dynFileName)
            print(dynFileName)
            upload.save(file_path)

        #returnJson = json.dumps({"fileName":dynFileName})
        returnJson["fileName"]= str(dynFileName)
        print(returnJson)

        return str(returnJson)

这是另一条有效的路线:

    @route('/imageDelete', method="POST")
    def imageDelete():
        response.content_type = "application/json"
        callback = request.query.callback
        file_name = request.query.file_name

        os.remove(pathToImage+"/uploads/"+str(file_name))

        returnJson = {"deleted":"true"}

0 个答案:

没有答案