Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileUpload: Ability to add file from variable #3044

Closed
Audiopolis opened this issue Jul 7, 2022 · 5 comments · Fixed by #3043 or #3132
Closed

FileUpload: Ability to add file from variable #3044

Audiopolis opened this issue Jul 7, 2022 · 5 comments · Fixed by #3043 or #3132
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@Audiopolis
Copy link

Audiopolis commented Jul 7, 2022

Describe the feature you would like to see added

Before today, we were on 7.2.1. We have two options for selecting a file: upload a local file or take a photo with your camera. When using the camera option (using react-webcam), we did the following in order to add it to the File

        // ...
	const fileUploadRef = useRef<FileUpload & { onFileSelect(event): void }>(null)

	const onCameraFinish = (file: File) => {
		setShowCamera(false)
		const event = {
			target: {
				files: [file],
			},
		}
		// Hack: Simulate selection of a file to add it to FileUpload component
		fileUploadRef.current?.onFileSelect(event)
	}

	return (
		<>
			<Camera isActive={isShowCamera} onFinish={onCameraFinish} />
			<FileUpload
				ref={fileUploadRef}
				multiple
				customUpload
				uploadHandler={customUploader}
				// ...
			/>
		</>
	)

After upgrading to 8.2.0, fileUploadRef.current?.onFileSelect is no longer defined.

We would like a way to add files to the component without going through the normal file selection process.

Is your feature request related to a problem?

We are unable to upload files gotten by other means than the normal file selection process.

Describe the solution you'd like

Some way of adding files to FileUpload's list of files programmatically.

Describe alternatives you have considered

I have looked at the defined properties of the ref and found no suitable members. I have considered using a different component for photo uploads, but this would be a major and unacceptable downgrade. I have considered downgrading, but this is not possible as we are at the end of a very much needed upgrade process. We need React 18 support.

Additional context

There may be a way of doing this that I'm not aware of, but it's not clear from docs or anything I've found on Google.

@Audiopolis Audiopolis added the Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add label Jul 7, 2022
@melloware melloware self-assigned this Jul 7, 2022
@melloware melloware added this to the 9.0.0 milestone Jul 7, 2022
@melloware
Copy link
Member

I think it's the same issue as #2893 which I just submitted a PR for.

@melloware melloware added Type: Bug Issue contains a defect related to a specific component. and removed Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add labels Jul 7, 2022
@Audiopolis
Copy link
Author

Yep, thank you and sorry about the duplicate.

@melloware
Copy link
Member

No worries! More people reporting it just means it's more urgent to fix!

@melloware melloware changed the title Ability to add file from variable FileUpload: Ability to add file from variable Jul 11, 2022
@melloware melloware added Resolution: Duplicate Issue has already been reported or a pull request related to same issue has already been submitted and removed Type: Bug Issue contains a defect related to a specific component. labels Jul 11, 2022
@mertsincan mertsincan removed this from the 9.0.0 milestone Jul 18, 2022
@mertsincan mertsincan removed the Resolution: Duplicate Issue has already been reported or a pull request related to same issue has already been submitted label Jul 18, 2022
@Audiopolis
Copy link
Author

Audiopolis commented Aug 3, 2022

This is still happening on 8.3.0

	const fileUploadRef = useRef<FileUpload & { onFileSelect(event): void }>(null)

	const onCameraFinish = (file: File) => {
		setShowCamera(false)
		const event = {
			target: {
				files: [file],
			},
		}
		fileUploadRef.current?.onFileSelect(event)  # onFileSelect is not a function
	}

@melloware melloware added this to the 9.0.0 milestone Aug 3, 2022
@melloware melloware added the Type: Bug Issue contains a defect related to a specific component. label Aug 3, 2022
@melloware melloware reopened this Aug 3, 2022
melloware added a commit to melloware/primereact that referenced this issue Aug 3, 2022
@melloware
Copy link
Member

My bad! Please review my PR: #3132

melloware added a commit to melloware/primereact that referenced this issue Aug 7, 2022
melloware added a commit to melloware/primereact that referenced this issue Aug 7, 2022
@mertsincan mertsincan modified the milestones: 9.0.0, 8.4.0 Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
3 participants