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

initialFiles not shown up #87

Closed
ameenazeemiacmedocs opened this issue Nov 21, 2019 · 5 comments
Closed

initialFiles not shown up #87

ameenazeemiacmedocs opened this issue Nov 21, 2019 · 5 comments

Comments

@ameenazeemiacmedocs
Copy link

I am getting an issue on Initial Files do not show up ,it shows like
image

instead of actual image. Below is the code that i am using

<DropzoneArea acceptedFiles={['image/jpeg', 'image/png', 'image/bmp']} showPreviews={true} showPreviewsInDropzone={true} showFileNamesInPreview={true} initialFiles={[https://images.pexels.com/photos/1909603/pexels-photo-1909603.jpeg`]}
filesLimit={1}
maxFileSize={1000 * 1000}
dropzoneText="Advertisement Image"
onChange={changeAdImage}

                                    />`
@lahoti-piyush
Copy link

i am also facing some issue.

@brizandrew
Copy link

I think I've figured out the problem. It looks like the ternary that decides whether to show a real image or this icon uses this helper function.

That function is returning "false" incorrectly on your image and mine because this other helper function is adding an extension even if the file has one in the URL.

For example your file is being named pexels-photo-1909603.jpeg.jpg by createFileFromURL and then isImage is saying jpeg.jpg is not a valid image extension.

I'm not sure what the best solution here is, maybe checking to see if the filename already has an extension before adding it.

@seanhaufler
Copy link

This logic change to the isImage function worked for me, feel free to use / submit a pull request if you like:

export function isImage(file) {
    const fileName = file.name || file.path;
    const match = /.*\.(.+)/.exec(fileName)
    if (!match || match.length < 2) {
        return false
    }
    const suffix = match[1]
    if (suffix === 'jpg' || suffix === 'jpeg' || suffix === 'bmp' || suffix === 'png') {
        return true;
    }
    return false
}

@Rambalac
Copy link

Rambalac commented Dec 23, 2019

Image does not need to have any extension to be an image.
If you want to get ContentType use HEAD request.
Or accept callback to allow developers to decide what icon should be used.

@faupol3
Copy link
Contributor

faupol3 commented Feb 18, 2020

Fix at #101

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants