Adobe Creative SDK for Web saving edited image

纵饮孤独 提交于 2019-12-06 03:49:54

The Image Editor onSave() method

onSave() is just a hook; it is the method called after the image save is complete. What you put inside of the onSave() method is entirely up to you.

Just to illustrate, you could 1) replace the original image element's source with the new edited image URL, then 2) close the editor:

onSave: function(imageID, newURL) {
    originalImage.src = newURL;
    featherEditor.close();
}

You could even just put a console log in there, but that wouldn't do much for the user.

Again, onSave() is just a hook that is used after the save is complete, and its content is completely up to you.

Posting to your server

The code you showed in your question is just an example of how you might post the data to your server using jQuery within the Image Editor's onSave() method. There is no requirement that you do it this way; you don't even have to use jQuery.

For clarity, here's a look at that example again:

$.post('/save', {url: newURL, postdata: 'some reference to the original image'})

The endpoint

The example above uses the jQuery post() method to hit a /save endpoint on your server. This endpoint could be anything you want it to be. If you have an endpoint on your server called /upload-image, you could use that instead.

In your case, at this endpoint would be the PHP script that handles the image file save and database update.

The post data

The second argument to post() is an object with the data that you want to pass. In this example, we're passing:

  1. the newURL of the edited image so your server can do something with it (see Important note below)
  2. a reference to the original image (arbitrarily named postdata here) so your server can know what image was edited

You can put anything you want in this object. It depends on what your server script needs. But at the bare minimum, I would think it would need the newURL and likely some way to reference the original image in your database.

Important note: as noted in the Creative SDK for web Image Editor guide, the newURL that you receive in the onSave() method is a temporary URL. It expires in 72 hours. That means that your server script needs to save the image itself to your server. If you only store the URL in your database, your images will start disappearing in 72 hours.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!