A lot of things have changed since the last 1.0.0 release. This document outlines all the changes that might need your attention during this process.
On 1.0.0, you had to configure your filestack api key like:
// config/environment.js
module.exports = function(environment) {
let ENV = {
//...
filestackKey: '<your-filestack-key>'
};
//...
}
Now you should:
// config/environment.js
module.exports = function(environment) {
let ENV = {
//...
'ember-filestack': {
apiKey: '<your-filestack-key>'
}
};
//...
}
On 1.0.0, you could configure custom CDNs like
// config/environment.js
module.exports = function(environment) {
let ENV = {
//...
filestackProcessCDN: '<your-process-cdn.cloudfront.net>',
filestackContentCDN: '<your-content-cdn.cloudfront.net>',
};
//...
};
Now you should:
// config/environment.js
module.exports = function(environment) {
let ENV = {
//...
'ember-filestack': {
apiKey: '<your filestack api key>',
customCDN: '<your-cdn.cloudfront.net>'
}
};
//...
};
Notice that there's only one CDN to configure now. That's because filestack no longer
uses https://process.filestackapi.com
urls. All files are accessed through https://cdn.filestackcontent.com
,
even if the url has transforms in it.
This is why only one CDN is needed now.
On 1.0.0 you would use the file picker using the ember-filestack-picker
component like:
const filestackPickerOptions = {
accept: ['image/*'],
maxSize: 10485760
};
export default Component.extend({
filestackPickerOptions,
actions: {
fileSelected(result) {
// the `filesUploaded` is an array of files you've just uploaded
console.log(result.filesUploaded);
},
onError(file, error) {
// ...
}
}
});
Now you would use something like:
or if you prefer with the new angle bracket invocation syntax (recommended):
You can use angle bracket invocation syntax with old versions of ember using ember-angle-bracket-invocation-polyfill.
Things to note:
- the component name changed from
ember-filestack-picker
to justfilestack-picker
. - each key of
options
can now be passed directly to the component instead of having to build a hash yourself - however, you can still use
@options={{someOptionsDefinedElsewhere}}
if you need to. These will be merged with the direct options explained above. - Custom actions like
onSelection
action are now replaced foronUploadDone
, for example. This is what the filestack library uses, and there's no need to rename that. It's just another option we pass in directly. - You can now pass in two different types of actions to react to errors:
onError
is triggered byember-filestack
itself when something goes wrong while initializing filestack or the picker. This is not triggered by the filestack library. It's not something very likely to occur, assuming that the api key is there and configs are correct.onFileUploadFailed
is triggered by the filestack library under the hood when the upload fails
- We just reference filestack's complete set of options here: https://filestack.github.io/filestack-js/interfaces/pickeroptions.html all of them are supported by this new component.
Generating filestack urls for files on 1.0.0 was done using the filestack-image
helper like:
Now we do:
Things to note:
- the helper name changed from
filestack-image
to justfilestack-url
, since we can link/transform other files that aren't images. - the handle/url is still passed in as the first and only positional parameter. Nothing changed.
- transformations also exactly the same as before. However, under the hood, we're not computing the url for the transformation ourselves anymore. We're realying on an updated version of the filestack library to do that for us. That's why it is wise to consult the transform options here: https://filestack.github.io/filestack-js/interfaces/transformoptions.html . These are the options that the helper supports because it passes them in directly to the filestack library.
On 1.0.0 you could access the filestack library instance like:
export default Component.extend({
//injecting the filestack object
filestack: service(),
someFunction: function(){
// Use the promise in case you are not sure that your component will be initialized after filestack has been loaded
this.get('filestack.promise').then(function(filestack){
// do something with filestack
});
// OR if you are sure filestack has already been loaded use:
this.get('filestack.instance')
}
});
Now you do it like:
import Component from '@ember/component';
import { inject as service } from '@ember/service';
export default Component.extend({
// inject the filestack service
filestack: service(),
async someFunction() {
// Use the promise in case you are not sure that your component will be initialized after filestack has been loaded
let filestack = await this.filestack.initClient();
// do something with filestack
}
});
Things to note:
- you need to make sure that filestack is initialized using the service's
initClient
method. - calling this method multiple times will initialize the filestack client only once, so this can be used as a getter for the filestack client instance
- the asynchronicity is due to the way ember-filestack lazily initializes filestack. If no one ever needs filestack related functionality in your app, ember-filestack waste any cpu resources with filestack. In fact, even the filestack library itself is loaded dynamically at runtime only if needed.
The underlying filestack library was also updated from ^0.11.4
to ^1.14.1
, so if you use filestack client directly,
please check if you need to update your code as well. Here is filestack-js changelog: https://github.com/filestack/filestack-js/blob/master/CHANGELOG.md