File upload does not work on Locaweb hosting

6

Locally I can upload and quietly save a file using the following code

Controller:

public ActionResult CriarProduto(FormCollection form, HttpPostedFileBase file)
{
   Produto produto = new Produto();
   ProdutoService prod = new ProdutoService();
   //Pego algumas infos do form e gravo o produto
   prod.Criar(produto);

  //Aqui começa a logica de upload da imagem
   var fileName = "";

            if (file != null && file.ContentLength > 0 && file.ContentLength < 1000000)
            {
                fileName = "produto" + produto.ProdutoId.ToString() + ".png";
                var path = Path.Combine(Server.MapPath("~/Content/img/"), fileName);
                file.SaveAs(path);
            }
  produto.Foto = fileName;
  prod.Atualizar(produto);

  return RedirectToAction("Produtos"); 
}

View:

// Parte do código - upload do arquivo
<div class="form-group">
            <div class="col-lg-4">
          <label class="control-label input-sm">Foto do produto</label>
            <input type="file" name="file" id="file" />
          </div>
        </div>

In this way I can correctly write the file in the folder I indicated and in the database I record the name of the file that I specified.

It turns out that when I host Locaweb, none of this works. He is writing to the database the name of the empty photo, that is, he does not even want to enter if to save the image. And it saves the product quietly in the database, just does not send the photo and the name in the Foto field.

Do I need to upload some more DLLs for the hosting?

    
asked by anonymous 01.08.2014 / 19:51

2 answers

2

I'll leave my comment in reply. So if another user has this problem, they can help.

Contact LocaWeb who care for these privileges. The problem is permissions, they are the ones that enable it.

At least in my case, it has been resolved this way.

    
04.08.2014 / 14:02
1

Everything indicates that what is happening is that you are not allowed to write to the directory, check with the company that provides you with the hosting service if you have this privilege it is not because your website is hosted that you have the rights to write information to the server.

    
04.08.2014 / 14:12