TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Dawood Abbas
NA
264
99k
upload canvas to project's folder using javascript and mvc?
Oct 15 2019 2:25 AM
I would like to save the my canvas into my project's folder 'Upload', so trying to convert it into image and then sending it to code behind and saving. But its getting whole web page screenshot not just canvas.
This is my javascript code :
html2canvas(document.body, {onrendered:
function
(canvas) {
var
mergedImage = canvas.toDataURL(
"image/png"
);
mergedImage = mergedImage.replace(
'data:image/png;base64,'
,
''
);
var
param = { imageData: mergedImage };
$http({
method:
'POST'
,
url:
'/Admin/MyController/UploadImage'
,
data: JSON.stringify(param),
dataType:
'JSON'
,
headers: {
'content-type'
:
'application/json'
}
}).then(
function
(response) { alert(
'Your photos successfully uploaded!'
);
}); } });
This is my c# code in mvc controller's file:
[HttpPost]
public
ContentResult UploadImage(
string
imageData)
{
try
{
string
fileNameWithPath = Server.MapPath(
"~/Images/SomeFolder/custom_name.png"
);
if
(!Directory.Exists(fileNameWithPath))
{
using
(FileStream fs =
new
FileStream(fileNameWithPath, FileMode.Create))
{
using
(BinaryWriter bw =
new
BinaryWriter(fs))
{
byte
[] data = Convert.FromBase64String(imageData);
bw.Write(data);
bw.Close();
} } } }
catch
(Exception ex) { }
return
Content(
"Uploaded"
); }
I just need to save canvas only into the my project's folder.
Reply
Answers (
0
)
How to change the _type value in elasticsearch using Nest?
How to get email body, receipt, sender and CC info using EWS