Upload image android to webservice asp.net

0

Good morning, I'm trying to upload an image of Android using an ASP MVC controller method but without success, could you give me some guidance?

Here I declare the Retrofit method

@POST("prueba")
Call<JsonElement> prueba(@Query("img") Bitmap img);

Next, the Android method by which I try to upload the previously loaded image into an ImageView

public void prueba() {
    MuniWebServices services = ApiMuniWeb.getApi().create(MuniWebServices.class);
    Bitmap bm = ((BitmapDrawable) img1.getDrawable()).getBitmap();

    Call<JsonElement> call = services.prueba(bm);

    call.enqueue(new Callback<JsonElement>() {
        @Override
        public void onResponse(Call<JsonElement> call, Response<JsonElement> response) {
            Toast.makeText(getContext(), response.message(), Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onFailure(Call<JsonElement> call, Throwable t) {
            Toast.makeText(getContext(), t.getMessage() + " - " + t.toString(), Toast.LENGTH_SHORT).show();
        }
    });
}

and finally this is the method in the ASP.MVC driver

Public Function prueba(img As Bitmap) As Codigo

    Try
        Dim format As Imaging.ImageFormat = Imaging.ImageFormat.Jpeg
        Dim fs As FileStream = New FileStream(System.Web.Hosting.HostingEnvironment.MapPath("~\paginas\img_reclamos") + "/prueba.jpg", FileMode.Create)
        img.Save(fs, format)
        fs.Close()
        fs.Dispose()

        Return obtenerCodeOK()
    Catch ex As Exception
        Return obtenerCodeError(ex.Message.ToString)
    End Try
End Function

The methods are connected correctly and the return of them is correct tmb, the problem is that I create an image in the server folder completely empty as the one shown below

    
asked by DavidC 30.07.2018 в 13:40
source

0 answers