sealcode / sealious

An extensible, declarative node framework
25 stars 2 forks source link

POST with file (mime: multipart/form-data) generates error 500 #183

Closed arkadiusz-wieczorek closed 9 years ago

arkadiusz-wieczorek commented 9 years ago

As you can see save_file function doesn't have reference to Sealious object. Adding var Sealious = require("sealious"); in file-manager.js solves problem, but this very ugly solution. We should rewrite save_file function, in file-manager.js we need to add reference to Dispatcher.

01:26:40.053 - error:   POST /api/v1/places
            from: 127.0.0.1, mime: multipart/form-data
            result: 
01:26:40.053 - error:  ReferenceError: Sealious is not defined
    at save_file (/home/arkadiusz/Projects/Placetag/placetag-app/node_modules/sealious/lib/core-services/file-manager.js:59:16)
    at FieldFileType.encode (/home/arkadiusz/Projects/Placetag/placetag-app/node_modules/sealious/lib/base-chips/field_type.file.js:27:36)
    at encode_value (/home/arkadiusz/Projects/Placetag/placetag-app/node_modules/sealious/lib/chip-types/resource-type-field.js:73:27)
    at encode_field_values (/home/arkadiusz/Projects/Placetag/placetag-app/node_modules/sealious/lib/chip-types/resource-type.js:145:49)
    at /home/arkadiusz/Projects/Placetag/placetag-app/node_modules/sealious/lib/core-services/resource-manager.js:28:32
    at bound (domain.js:254:14)
    at runBound (domain.js:267:12)
    at tryCatcher (/home/arkadiusz/Projects/Placetag/placetag-app/node_modules/bluebird/js/main/util.js:26:23)
    at Promise._settlePromiseFromHandler (/home/arkadiusz/Projects/Placetag/placetag-app/node_modules/bluebird/js/main/promise.js:503:31)
    at Promise._settlePromiseAt (/home/arkadiusz/Projects/Placetag/placetag-app/node_modules/bluebird/js/main/promise.js:577:18)
    at Async._drainQueue (/home/arkadiusz/Projects/Placetag/placetag-app/node_modules/bluebird/js/main/async.js:128:12)
    at Async._drainQueues (/home/arkadiusz/Projects/Placetag/placetag-app/node_modules/bluebird/js/main/async.js:133:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/home/arkadiusz/Projects/Placetag/placetag-app/node_modules/bluebird/js/main/async.js:15:14)
    at processImmediate [as _immediateCallback] (timers.js:367:17)
ReferenceError: Sealious is not defined
    at save_file (/home/arkadiusz/Projects/Placetag/placetag-app/node_modules/sealious/lib/core-services/file-manager.js:59:16)
    at FieldFileType.encode (/home/arkadiusz/Projects/Placetag/placetag-app/node_modules/sealious/lib/base-chips/field_type.file.js:27:36)
    at encode_value (/home/arkadiusz/Projects/Placetag/placetag-app/node_modules/sealious/lib/chip-types/resource-type-field.js:73:27)
    at encode_field_values (/home/arkadiusz/Projects/Placetag/placetag-app/node_modules/sealious/lib/chip-types/resource-type.js:145:49)
    at /home/arkadiusz/Projects/Placetag/placetag-app/node_modules/sealious/lib/core-services/resource-manager.js:28:32
    at bound (domain.js:254:14)
    at runBound (domain.js:267:12)
    at tryCatcher (/home/arkadiusz/Projects/Placetag/placetag-app/node_modules/bluebird/js/main/util.js:26:23)
    at Promise._settlePromiseFromHandler (/home/arkadiusz/Projects/Placetag/placetag-app/node_modules/bluebird/js/main/promise.js:503:31)
    at Promise._settlePromiseAt (/home/arkadiusz/Projects/Placetag/placetag-app/node_modules/bluebird/js/main/promise.js:577:18)
    at Async._drainQueue (/home/arkadiusz/Projects/Placetag/placetag-app/node_modules/bluebird/js/main/async.js:128:12)
    at Async._drainQueues (/home/arkadiusz/Projects/Placetag/placetag-app/node_modules/bluebird/js/main/async.js:133:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/home/arkadiusz/Projects/Placetag/placetag-app/node_modules/bluebird/js/main/async.js:15:14)
    at processImmediate [as _immediateCallback] (timers.js:367:17)
Debug: internal, implementation, error 
    Error: ENOENT, open '/home/arkadiusz/Projects/Placetag/placetag-app/uploaded_files/uxks0c1kax'
    at Error (native)
kuba-orlik commented 9 years ago

Ok, I've made some changes to the FileManager. Does the error still occur in 0.5.2?

arkadiusz-wieczorek commented 9 years ago

At now there is other error. Maybe I have mistakes in main.js

zbox@zbox-ZBOX-ID83:~/Projects/Placetag/placetag-app$ sudo node .
10:03:00.557 - info: Detected plugin sealious-www-server
/home/zbox/Projects/Placetag/placetag-app/node_modules/sealious/lib/chip-types/resource-type.js:11
        throw new Sealious.Errors.DeveloperError("Tried to create a resource-type wi
              ^
Error: Tried to create a resource-type without a declaration
    at new SealiousErrors.Error (/home/zbox/Projects/Placetag/placetag-app/node_modules/sealious/lib/response/error.js:6:12)
    at new SealiousErrors.DeveloperError (/home/zbox/Projects/Placetag/placetag-app/node_modules/sealious/lib/response/error.js:85:12)
    at ResourceType (/home/zbox/Projects/Placetag/placetag-app/node_modules/sealious/lib/chip-types/resource-type.js:11:9)
    at Object.<anonymous> (/home/zbox/Projects/Placetag/placetag-app/main.js:10:14)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3
kuba-orlik commented 9 years ago

That's because the ResourceType API changed a little bit in 0.5.0. You chould change all your resource type declratations from

new Sealious.ChipTypes.ResourceType("type_name", {/*rest of the declaration*/})

to

new Sealious.ChipTypes.ResourceType({name: "type_name", /* rest of the declaration*/})

In your application's code.

arkadiusz-wieczorek commented 9 years ago

Ok, I changed this, at now I can't send POST/PATCH, only DELETE works.

10:18:03.665 - error:   POST /api/v1/places
            from: 127.0.0.1, mime: multipart/form-data
            result: failed - There are problems with some of the provided values
Error: There are problems with some of the provided values
    at new SealiousErrors.Error (/home/zbox/Projects/Placetag/placetag-app/node_modules/sealious/lib/response/error.js:6:12)
    at new SealiousErrors.ValidationError (/home/zbox/Projects/Placetag/placetag-app/node_modules/sealious/lib/response/error.js:21:12)
    at null.<anonymous> (/home/zbox/Projects/Placetag/placetag-app/node_modules/sealious/lib/chip-types/resource-type.js:136:11)
    at bound (domain.js:254:14)
    at runBound (domain.js:267:12)
    at tryCatcher (/home/zbox/Projects/Placetag/placetag-app/node_modules/bluebird/js/main/util.js:26:23)
    at Promise._settlePromiseFromHandler (/home/zbox/Projects/Placetag/placetag-app/node_modules/bluebird/js/main/promise.js:503:31)
    at Promise._settlePromiseAt (/home/zbox/Projects/Placetag/placetag-app/node_modules/bluebird/js/main/promise.js:577:18)
    at Promise._settlePromises (/home/zbox/Projects/Placetag/placetag-app/node_modules/bluebird/js/main/promise.js:693:14)
    at Async._drainQueue (/home/zbox/Projects/Placetag/placetag-app/node_modules/bluebird/js/main/async.js:123:16)
    at Async._drainQueues (/home/zbox/Projects/Placetag/placetag-app/node_modules/bluebird/js/main/async.js:133:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/home/zbox/Projects/Placetag/placetag-app/node_modules/bluebird/js/main/async.js:15:14)
    at processImmediate [as _immediateCallback] (timers.js:367:17)

My structure rest of the declaration

var places = new Sealious.ChipTypes.ResourceType({name: "places",
    fields:[
        {name: "name", type: "text"},
        {name: "address", type: "text"},
        {name: "city", type: "text"},
        {name: "country", type: "text"},

        {name: "category", type: "category"},
        {name: "subcategory", type: "subcategory"},

        {name: "description", type: "text"},
        {name: "votes", type: "int"},
        {name: "sum", type: "int"},
        {name: "globalRate", type: "int"},
        {name: "myRate", type: "int"},
        {name: "longitude", type: "float", required: true}, //52 dlugosc
        {name: "latitude", type: "float", required: true},  //16 szerokosc
        //files
        {name: "image", type: "file", params: {no_file_value: "/img/places/default.jpg"}},
        {name: "image_name", type: "text"},

        //to compare
        {name: "owner_id", type: "text"}
    ],
    access_strategy: "public"
});
kuba-orlik commented 9 years ago

Could you post the HTTP API response for a POST request?

arkadiusz-wieczorek commented 9 years ago

I'm surprised

image

kuba-orlik commented 9 years ago

Oh, that's right, it's caused by another API change in the 0.5.0 beta - field-type's isProperValue method takes context as it's first argument, and new_value as second, so probably just changing

my_field_type.prototype.isProperValue = function(new_value){//...

to

my_field_type.prototype.isProperValue = function(context, new_value){//...

should help.

If in doubt, see field-type api reference :)

arkadiusz-wieczorek commented 9 years ago

Thanks, everything works. I close issue :)