Hello,
I have a content type: User Profile. It has a binary field I am using to store an image. I am updating the contentlets using AJAX PUT from the client side. (My server java / plugin skills are not good/inexistent at this point).
If the user wants to remove the existing image from the front end, I would like to be able to remove the image from the contentlet (or alternatively replace it with a generic small image (like a user avatar) or just replace it with nothing).
I tried the following but was not successful (Note: I did not get a JavaScript error, nor a dotCMS server error on log):
Am I doing something wrong? Can someone please suggest a way to accomplish what I am trying to do?
Below are my attempts.
Thank you!
Mube
Attempt 1: I tried to overwrite the image with null by appending the 'file' key with a value of null (I have to admit this was a guess…)
dataform.append(‘file', null);
Attempt 2: I tried to upload an image from the server that will replace the existing image:
2.1
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200){
console.log(this.response, typeof this.response);
dataform.append('file', this.response);
}
}
xhr.open('GET', 'http://[server IP address]/application/themes/orizonto/images/layout/smiley2.png',true);
xhr.responseType = 'blob';
xhr.send();
2.2
fetch('http://[server IP address]/application/themes/orizonto/images/layout/smiley2.png’)
.then(res => res.blob()) // Gets the response and returns it as a blob
.then(blob => {
dataform.append(‘file', blob);
});
The AJAX code:
$.ajax({
url: '/api/content/publish/1',
type: 'PUT',
cache:false,
data: dataform,
processData: false,
contentType: false,
success: function(data, status, xhr) {
$('#profileImageHeader').attr("src", $('#profileImage').attr('src'));
bootstrap_alert.success('Profile updated successfully');
console.log("works!");
var a = xhr.getAllResponseHeaders();
var id = a.substring(a.indexOf('identifier: ') + 'identifier: '.length , a.indexOf('\n', a.indexOf('identifier: ') + 'identifier: '.length));
},
error: function(data,status,xhr) {
bootstrap_alert.clear();
enableRequestBtn();
console.log(data);
bootstrap_alert.danger('Your profile could not be updated. Please check your entries and try again');
},
});
--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+unsubscribe@googlegroups.com.
To post to this group, send email to dot...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/e6015a01-c3f9-492b-85fa-2024012eae3d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+unsubscribe@googlegroups.com.
To post to this group, send email to dot...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/a6739556-6e14-44d0-9518-5c1c5bcb9d74%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+unsubscribe@googlegroups.com.
To post to this group, send email to dot...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/4bf0a8ad-2fe1-4b30-99ce-b6fcf91aadb9%40googlegroups.com.