json-editor icon indicating copy to clipboard operation
json-editor copied to clipboard

File upload, How to config a server handle url?

Open ilzlsm opened this issue 6 years ago • 5 comments

ilzlsm avatar Jan 05 '19 10:01 ilzlsm

https://github.com/json-editor/json-editor/blob/fa39ffba6b332f3ed62cc6810e9dfd449240d219/README.md#usage

schmunk42 avatar Jan 06 '19 22:01 schmunk42

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

theamnesic avatar Dec 03 '19 12:12 theamnesic

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 avatar Jan 27 '22 17:01 theamnesic

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

schmunk42 avatar Jan 27 '22 21:01 schmunk42

@schmunk42 Yep, sorry !

theamnesic avatar Jan 28 '22 10:01 theamnesic