jdorn / json-editor

JSON Schema Based Editor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

File upload, How to config a server handle url?

ilzlsm opened this issue · comments

Hi!

Unfortunately, the example doesn't work.

I've got large files, so I can't use base64, I have to upload files on the server.

I've got this schema:

"Image": {
  type: "string",
  format: "url",
  options: {
    upload: true
  },
  "links": [
    {
        "href": "{{self}}"
    }
  ]
}

and this handler:

  JSONEditor.defaults.options.upload = function(type, file, cbs) {
    if (type === 'root.upload_fail') cbs.failure('Upload failed');
    else {
      var tick = 0;

      var tickFunction = function() {
        tick += 1;
        // console.log('progress: ' + tick);

        if (tick < 100) {
          cbs.updateProgress(tick);
          window.setTimeout(tickFunction, 50)
        } else if (tick == 100) {
          cbs.updateProgress();
          window.setTimeout(tickFunction, 500)
        } else {
          cbs.success(file.name);
        }
      };

      window.setTimeout(tickFunction)
    }
  };

Can you tell me if the schema is good, and the right way to upload the file please ?

For example, format: "file" looks more logical but hide the Upload button.
I can't find documentation about that...

Thanks!

— G

Hi,

I upgraded to 2.6.1 and it seems this schema doesn't work anymore since 2.0.0 alpha 0 :

"Image": {
  "type": "string",
  "format": "url",
  "options": {
  "upload": true
},

The field before:
Capture d’écran 2022-01-27 à 18 40 05

After update:
Capture d’écran 2022-01-27 à 18 40 21

I haven't any console error.

As I said previously, I've got large files so I can't use base64.

Thanks for your help!

@theamnesic I think you're in the wrong repo, please check it here: https://github.com/json-editor/json-editor

@schmunk42 Yep, sorry !