File upload does not work on Locaweb hosting

Asked

Viewed 1,410 times

6

Locally I can upload the file and save quietly in a folder 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>

This way I can correctly write the file in the folder I indicated and in the database I write the name of the file I specified.

It turns out when I stay at Locaweb none of this works. He’s recording in the database the name of the empty photo, IE, he doesn’t even enter the if to save the image. And it writes the product peacefully in the database, just does not send the photo and the name in the field Foto.

Need to upload some extra DLL for hosting?

  • 2

    Rafael, I’ve been through this problem. I contacted Locaweb and they solved it. Here in my case the problem was permissions, there were they who enabled permissions.

  • Worst I called there and the attendant did not know how to solve my problem. I will try again.

  • 1

    I also came across this problem and got the solution in the same way that Diego said. But my upload works only in production. Via localhost I cannot upload any files to Locaweb FTP

  • 1

    Here gave this error @Rafaelmoura: "Access to the path 'path' is denied."

  • 1

    I did it! That’s right, permission problem!

2 answers

2

I’ll leave my comment as an answer. So if another user is having this problem, it might help.

Contact Locaweb and they take care of these privileges. The problem is permissions, they are the ones that enable.

At least in my case, it was solved this way.

1

Everything indicates that what is happening is that you are not allowed to record in the directory, check with the company that provides you the hosting service if you have this privilege is not because your hosted site ta you have the rights to record information on the server.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.