fix(upload): fix upload url for relationship blocks
This commit is contained in:
parent
2d5b70b3f7
commit
bb83face08
@ -5,6 +5,7 @@ import { isArr, isValid, toArr as toArray } from '@formily/shared';
|
|||||||
import { UploadFile } from 'antd/es/upload/interface';
|
import { UploadFile } from 'antd/es/upload/interface';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { useAPIClient } from '../../../api-client';
|
import { useAPIClient } from '../../../api-client';
|
||||||
|
import { useBlockRequestContext, useSourceIdFromParentRecord } from '../../../block-provider/BlockProvider';
|
||||||
import { UPLOAD_PLACEHOLDER } from './placeholder';
|
import { UPLOAD_PLACEHOLDER } from './placeholder';
|
||||||
import type { IUploadProps, UploadProps } from './type';
|
import type { IUploadProps, UploadProps } from './type';
|
||||||
|
|
||||||
@ -171,6 +172,8 @@ export function useUploadProps<T extends IUploadProps = UploadProps>({ serviceEr
|
|||||||
};
|
};
|
||||||
|
|
||||||
const api = useAPIClient();
|
const api = useAPIClient();
|
||||||
|
const { props: blockProps } = useBlockRequestContext();
|
||||||
|
const sourceId = useSourceIdFromParentRecord();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...props,
|
...props,
|
||||||
@ -185,6 +188,11 @@ export function useUploadProps<T extends IUploadProps = UploadProps>({ serviceEr
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
formData.append(filename, file);
|
formData.append(filename, file);
|
||||||
|
|
||||||
|
if (blockProps?.association) {
|
||||||
|
action = `${blockProps?.association.split('.')[0]}/${sourceId}/${action}`;
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line promise/catch-or-return
|
// eslint-disable-next-line promise/catch-or-return
|
||||||
api.axios
|
api.axios
|
||||||
.post(action, formData, {
|
.post(action, formData, {
|
||||||
|
Loading…
Reference in New Issue
Block a user