在邮递员中它对我有用,我认为问题在于生成表单数据或发送给Alfresco的表单类型
服务:在服务中,他进行了观察,将文档发送到Alfresco。目前,票证是在此代码之外生成的,但是..
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { AlfrescoApi } from 'alfresco-js-api';
@Injectable({
providedIn: 'root' })
export class AlfrescoService {
public ticket = 'TICKET_7202a894801a8a7caa5da6c5a86cf4c1f40c6f4e';
constructor( public peticion: HttpClient ) {}
uploadFile( formData) {
const settings = {
headers: {
'cache-control': 'no-cache',
},
'data': formData
};
console.log(settings);
return this.peticion.post( `http://localhost:8080/alfresco/s/api/upload?alf_ticket=${this.ticket}`, settings ); } }
组件: 在此组件中,我调用将文件发送到Alfresco的服务方法。
import { Component, OnInit } from '@angular/core';
import { AlfrescoService } from '../../servicios/alfresco.service';
import { FormsModule } from '@angular/forms';
@Component({
selector: 'app-subir',
templateUrl: './subir.component.html',
styleUrls: ['./subir.component.css']
})
export class SubirComponent implements OnInit {
public file;
public uploadFiles: Array < File > ;
constructor( private alfresco: AlfrescoService ) { }
ngOnInit() {}
fileChange( event ) {
this.uploadFiles = event.target.files;
}
upload() {
const formData = new FormData();
formData.append('filedata', this.uploadFiles[0]);
formData.append('destination', "workspace://SpacesStore/d148d33d-b615-412c-8f23-e1efcca1dcd1");
formData.append('uploaddirectory', "soin");
this.alfresco.uploadFile( formData ).subscribe( respuesta => {
console.log(respuesta);
}); } }
查看
<div class="mtop mleft">
<h3>Cargar Archivo en ALFRESCO</h3>
</div>
<form enctype="multipart/form-data" method="POST">
<input
value="Upload"
name="file"
type="file"
(change)="fileChange($event)" /><br>
</form>
<button type="submit" class="btn btn-success mtop mleft"
(click)="upload()" >SUBIR </button>
我需要帮助。