sendOnMyimager(file, client_key, project_key)
Purpose:
The sendOnMyimager
function allows developers to upload images to a MyImager account and store them in the cloud. After uploading, the function returns essential information about the image, such as:
- URL: A direct link to access the uploaded image.
- Name: The name of the uploaded image file.
- Size: The size of the image in bytes.
This function simplifies the image upload process, providing a seamless way for developers to store and retrieve image data programmatically.
Parameters:
- file (File or Buffer):
The image file you want to upload to MyImager. This could be a file object, a Buffer (binary data), or a path to the image file. It should contain image data (e.g., JPEG, PNG, GIF, etc.).
- client_key (string):
A unique client key associated with the developer's MyImager account. This key ensures the developer has permission to upload images.
- project_key (string):
A unique project key for categorizing and managing uploaded images within a specific project or account.
Returns:
The function returns an object containing the following properties:
- url (string): A direct link (URL) to the uploaded image stored on MyImager.
- name (string): The name of the uploaded image file, the same as when uploaded.
- size (number): The size of the uploaded image in bytes.
Example: Upload an Image to MyImager
const file = document.querySelector('input[type="file"]').files[0]; // Example: Get the image from a file input field
const client_key = 'your-client-key';
const project_key = 'your-project-key';
sendOnMyimager(file, client_key, project_key)
.then(response => {
// Successfully uploaded image, and received the image details
console.log("Image uploaded successfully!");
console.log("Image URL:", response.url);
console.log("Image Name:", response.name);
console.log("Image Size:", response.size, "bytes");
})
.catch(error => {
console.error("Error uploading image:", error);
});
This example demonstrates how to upload an image using the sendOnMyimager
function. It retrieves the image from a file input, uploads it, and logs details like the URL, name, and size.