Steps:
- Install
@bytescale/upload-widget
- Uninstall
uploader
- Replace
"uploader"
with"@bytescale/upload-widget"
in yourimport
statements. - Replace
uploader
withupload-widget
in all CSS class name overrides (if you have any). - Replace
Uploader({apiKey}).open(params)
withUploadWidget.open({apiKey, ...params })
- As such
.open(...)
now takes a mandatory configuration object, withapiKey
being the only required field.
- As such
- Replace
onUpdate: (files) => {}
withonUpdate: ({uploadedFiles}) => {}
. beginAuthSession
andendAuthSession
are now static methods onAuthManager
from the@bytescale/sdk
NPM package.url
is now a static method onUrlBuilder
from the@bytescale/sdk
NPM package.onValidate
has been replaced withonPreUpload
: you should return an object of{errorMessage: "your error message"}
instead of"your error message"
. (This can also be a promise.)
import { Uploader } from "uploader";
const uploader = Uploader({
apiKey: "free"
});
//
// Uploading files...
//
uploader
.open({
multi: true,
onValidate: async file => "My Custom Error Message"
})
.then(files => {
if (files.length === 0) {
console.log("No files selected.");
} else {
console.log("Files uploaded:");
console.log(files.map(f => f.fileUrl));
}
})
.catch(err => {
console.error(err);
});
//
// Making URLs...
//
uploader.url("/my-uploaded-image.jpg", "thumbnail");
//
// JWT authorization...
//
await uploader.beginAuthSession("https://my-auth-url", async () => ({ Authorization: "Bearer AuthTokenForMyApi" }));
import { UploadWidget } from "@bytescale/upload-widget";
import { AuthManager, UrlBuilder } from "@bytescale/sdk";
//
// Uploading files...
//
UploadWidget.open({
apiKey: "free",
multi: true,
onPreUpload: async file => ({ errorMessage: "My Custom Error Message" })
})
.then(files => {
if (files.length === 0) {
console.log("No files selected.");
} else {
console.log("Files uploaded:");
console.log(files.map(f => f.fileUrl));
}
})
.catch(err => {
console.error(err);
});
//
// Making URLs...
//
UrlBuilder.url({
accountId: "your-account-id",
filePath: "/my-uploaded-image.jpg",
options: {
transformation: "preset",
transformationPreset: "thumbnail"
}
});
//
// JWT authorization...
//
await AuthManager.beginAuthSession({
accountId: "your-account-id",
authUrl: "https://my-auth-url",
authHeaders: async () => ({ Authorization: "Bearer AuthTokenForMyApi" })
});
Bytescale migration guides listed below:
- Migrating from
upload-js
to@bytescale/sdk
- Migrating from
uploader
to@bytescale/upload-widget
- Migrating from
react-uploader
to@bytescale/upload-widget-react
- Migrating from
angular-uploader
to@bytescale/upload-widget-angular
- Migrating from
@upload-io/vue-uploader
to@bytescale/upload-widget-vue
- Migrating from
@upload-io/jquery-uploader
to@bytescale/upload-widget-jquery