نمایش نتایج 1 تا 2 از 2

نام تاپیک: خطای Unsupported Media Type

Threaded View

پست قبلی پست قبلی   پست بعدی پست بعدی
  1. #1

    خطای Unsupported Media Type

    ســلام

    برای آپلود عکس مطابق با آموزشی این کنترلر رو ساختم


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Http;
    using Microsoft.AspNetCore.Mvc;
    using System.IO;

    namespace imageuploadapi.Controllers
    {
    [Route("api/[controller]")]
    [ApiController]


    public class ImageuploadController : ControllerBase
    {
    public static IWebHostEnvironment _environment;
    public ImageuploadController (IWebHostEnvironment environment)
    {
    _environment = environment;
    }

    public class Fileuploadapi
    {
    public IFormFile files { get; set; }
    }
    [HttpPost]
    public async Task<string> Post(Fileuploadapi objfile)
    {
    try
    {
    if (objfile.files.Length > 0)
    {
    if (!Directory.Exists(_environment.WebRootPath + "\\upload\\"))
    {
    Directory.CreateDirectory(_environment.WebRootPath + "\\upload\\");
    }

    using (FileStream fileStream = System.IO.File.Create(_environment.WebRootPath + "\\upload\\" + objfile.files.FileName))
    {
    objfile.files.CopyTo(fileStream);
    fileStream.Flush();
    return "\\upload\\" + objfile.files.FileName;
    }
    }
    else
    {
    return "Failed";
    }
    }

    catch (Exception ex)
    {

    return ex.Message.ToString();
    }


    }

    }


    }





    و این هم فایل Startup


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Http;
    using Microsoft.AspNetCore.HttpsPolicy;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Hosting;
    using Microsoft.Extensions.Logging;

    namespace imageuploadapi
    {
    public class Startup
    {
    public Startup(IConfiguration configuration)
    {
    Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {

    services.AddControllers();


    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
    if (env.IsDevelopment())
    {
    app.UseDeveloperExceptionPage();
    }
    else
    {
    app.UseHsts();
    }

    app.UseHttpsRedirection();

    app.UseRouting();

    app.UseAuthorization();
    app.UseStaticFiles();

    app.UseEndpoints(endpoints =>
    {
    endpoints.MapControllers();
    });

    app.Run(async (context) => {
    await context.Response.WriteAsync("could not find Anything");
    });
    }
    }
    }







    و این هم شات از ارسال فایل با نرم افزار Postman
    عکس های ضمیمه عکس های ضمیمه

تاپیک های مشابه

  1. خطای unsupported هانگام اجرای برنامه
    نوشته شده توسط hhaaddii1363 در بخش C#‎‎
    پاسخ: 0
    آخرین پست: چهارشنبه 17 بهمن 1397, 10:51 صبح
  2. خطا Unable to create a constant value of type 'Anonymous type'. Only primitive types ('such as Int32
    نوشته شده توسط spicirmkh در بخش دسترسی به داده ها (ADO.Net و LINQ و ...)
    پاسخ: 1
    آخرین پست: چهارشنبه 07 تیر 1391, 17:55 عصر
  3. سوال: پیغام خطای ( clould not convert variant of type(null) into type(string هنگام شروع برنامه ؟
    نوشته شده توسط ehp_kz6597 در بخش بانک های اطلاعاتی در Delphi
    پاسخ: 2
    آخرین پست: چهارشنبه 13 بهمن 1389, 08:15 صبح
  4. Unsupported filter type
    نوشته شده توسط saeidejafari در بخش PHP
    پاسخ: 2
    آخرین پست: چهارشنبه 13 شهریور 1387, 13:49 عصر

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •