亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Angular 8 將圖像上傳到 ApiController c# 從 Angular 7

Angular 8 將圖像上傳到 ApiController c# 從 Angular 7

C#
一只斗牛犬 2023-09-09 16:15:58
我正在使用 Angular 8。我將圖像發送到我的 ApiController 來保存圖像。我在 Angular 7 之前使用過,一切正常,升級到 Angular 8 后我沒有收到該文件。當我發送時,我在控制臺中看到文件的名稱和長度,但在 Api 中沒有看到它。我在這里缺少什么?我的角度 tsimport { timeout } from 'rxjs/operators';import { UserClaims } from './../../authentication/models/user-claims.model';import { PrivateZoneLoginService } from './../private-zone-login.service';import { Component, OnInit } from '@angular/core';import { MatBottomSheetRef } from '@angular/material/bottom-sheet';import { HttpClient } from '@angular/common/http';import { LocalStorageService } from 'src/app/app-services/local-storage.service';import { PrivateZoneConstants } from '../private-zone-constans';@Component({  selector: 'app-bottom-sheet',  templateUrl: './bottom-sheet.component.html',  styleUrls: ['./bottom-sheet.component.css']})export class BottomSheetComponent implements OnInit {  token = this.pzLogin.userLoginAccessToken;  public imagePath;  imgURL: any = this.pzLogin.UserLoginClaims.ImageUrl;  public message: string;  fileData = new FileReader();  reader = new FileReader();  fileUploaded: boolean = false;   loading: boolean = false;  constructor(    private _bottomSheetRef: MatBottomSheetRef<BottomSheetComponent>,    private http: HttpClient, private pzLogin: PrivateZoneLoginService,    private localStorageService: LocalStorageService) { }  openLink(event: MouseEvent): void {    this._bottomSheetRef.dismiss();    event.preventDefault();  }  ngOnInit() {  }  preview(event) {    if (event.files.length === 0) {      return;    }    const mimeType = event.files[0].type;    if (mimeType.match(/image\/*/) == null) {      this.message = 'Only images are supported.';      return;    }    const fileSize = event.files[0].size;    if (fileSize > 500839) {      this.message = 'Maximum upload file size 200 kb.';      return;    }
查看完整描述

1 回答

?
慕少森

TA貢獻2019條經驗 獲得超9個贊

您需要自己添加標題。


并檢查您的 HttpInterceptor 是否不會覆蓋您的標頭


這將解決問題


const HttpUploadOptions = new HttpHeaders();

HttpUploadOptions.append('Content-Type', 'multipart/form-data');

HttpUploadOptions.append('Accept', 'image/x-png,image/gif,image/jpeg');


this.http.post(PrivateZoneConstants.UploadUserImage, formData, 

  {

  headers: HttpUploadOptions,

  reportProgress: true

}).subscribe(res => {

    this.localStorageService.setItem('UserLoginClaims', res);

    this.fileUploaded = true;

    this.loading = false;

    this._bottomSheetRef.containerInstance.enter();

  });


查看完整回答
反對 回復 2023-09-09
  • 1 回答
  • 0 關注
  • 130 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號