LWC에서 apex 클래스 속성을 직접 바인딩 할 수 있습니까?-apex로 25MB 파일 업로드 (힙 크기 문제)?

Aug 21 2020

다음과 같은 lwc 구성 요소가 있습니다.

import { LightningElement } from 'lwc';
import {saveAttachment} from '@salesforce/apex/DocumentController.saveAttachment'

export default class FileUpload extends LightningElement {

  fileSelectionHandler() {
   // some logic to get the file
  }
  
  uploadFile() {
    saveAttachment({parentId: 'a0H3I000001SsylUAC'})
    .then(() => {
     // some code here
    })
    .catch(() => {
    // some code here
    })

  }
}

html 템플릿은 다음과 같습니다.

<template>
  <input type="file" onchange={fileSelectionHandler}>
  <button onclick={}>Upload</button>
</template>

그리고 다음과 같은 정점 클래스 :

public without sharing class DocumentController {

  @AuraEnabled
  public static string saveAttachment(String parentId) {
    Attachment attach = new Attachment();
    attach.Name = 'test.pdf';
    attach.ParentId = parentId;
    // attach.Body ==> this part should come from lwc

    insert attach;
    return attach.Id;
  }
}

내가 필요한 것은 위의 apex 클래스의 attach 를 템플릿에 직접 연결 하여 아래의 visualforce 페이지 입력 파일 구성 요소와 같이 apex 클래스 의 attach 에 직접 blob을 가져올 수있는 방법입니다.

<apex:inputfile style="" value="{!attach.body}" filename="{!attach.name}" contentType="{!attach.ContentType}"/>

여기에서 선택한 파일을 attach.body에 직접 할당합니다 . 마찬가지로 attach.Body 에서 blob을 사용할 수 있도록 lwc에 직접 연결 을 바인딩 수있는 파일이 있습니다. 이것은 apex의 힙 크기 문제없이 최대 25MB와 같은 큰 첨부 파일을 업로드하는 데 도움이 될 것입니다.

어떤 도움이라도 대단히 감사하겠습니다. 미리 감사드립니다.

참고 : 조명을 사용하고 있으므로 여기 에서 번개 파일 업로드를 사용할 수 없습니다.

답변

1 sfdcfox Aug 21 2020 at 00:59

일종의 API를 사용해야합니다. Apex에는 6MB 힙 제한이 있으므로 직접 바인딩해도 도움이되지 않으며 최대 페이로드 크기 (4MB)도 있으므로 합리적으로 업로드 할 수있는 가장 큰 파일은 약 3MB이며 base64를 포함합니다. 부호화.