Asp.Net Upload Imagem
Good afternoon!
I have problems uploading images to a defined folder. As you can see, in my code I can upload to the cloudinary root, but not to a specific folder I created.
Cloudinary cloudinary = new Cloudinary(account);
string NomeImagem = "";
string TipoImagem = "";
string Versao = "";
byte[] binData = null;
string result = string.Empty;
if (Request.Files.Count > 0)
{
if (Request.Files["FotoURL"].ContentLength > 0)
{
using (BinaryReader b = new BinaryReader(Request.Files["FotoURL"].InputStream))
{
binData = b.ReadBytes(Request.Files["FotoURL"].ContentLength);
}
string teste = Convert.ToBase64String(binData);
byte[] imageBytes = Convert.FromBase64String(Convert.ToBase64String(binData));
using (MemoryStream ms = new MemoryStream(imageBytes))
{
DirectoryInfo dir = new DirectoryInfo(Server.MapPath("."));
string diretorio = dir.FullName.ToString();
try
{
var uploadParams = new ImageUploadParams()
{
File = new FileDescription(IdUsuario + "Perfiltemp.jpg", ms)
};
var uploadResult = cloudinary.Upload(uploadParams);
NomeImagem = uploadResult.JsonObj["public_id"].ToString();
TipoImagem = uploadResult.Format.ToString();
Versao = "v" + uploadResult.Version.ToString();
dados += "&FotoURL=http://res.cloudinary.com/diretor/aceleramei/image/upload/" + Versao + "/" + NomeImagem + "." + TipoImagem;
}
catch (Exception e)
{
string msg = e.ToString();
var uploadParams = new ImageUploadParams()
{
File = new FileDescription(@"" + Server.MapPath("~") + "\\Content\\layout\\img\\300x200.gif")
};
var uploadResult = cloudinary.Upload(uploadParams);
NomeImagem = uploadResult.JsonObj["public_id"].ToString();
TipoImagem = uploadResult.Format.ToString();
Versao = "v" + uploadResult.Version.ToString();
dados += "&FotoURL=http://res.cloudinary.com/diretor/image/upload/" + Versao + "/" + NomeImagem + "." + TipoImagem;
}
}
-
Hi,
Please refer to this thread: https://support.cloudinary.com/hc/en-us/community/posts/360006627659-Upload-picture-folder-Asp-Net
0
Post is closed for comments.
Comments
1 comment