question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.link is not a function when retrieving multiple files

See original GitHub issue

I am having issues with using useTracker to retrieve a query of files: when writing:

const files = useTracker(() =>
    MedicalStorage.find({ meta: { tag } }).fetch()
  );

and later using inside a component:

{files.map((file) => (
        <div>
          <a
            href={file.link()}
            download={file.name}
            key={file._id}
            target="_parent"
          >
            download {file.name}
          </a>
          <button type="button" onClick={remove(file._id)}>
            delete
          </button>
        </div>
      ))}

I am getting the error: file.link is not a function. When using just .findOne() everything works as intended. I tried using forEach and tried to generate the links into a static array in the tracker and then returning it but the same error occurred there. I am receiving the file object as viewed by the console.log(file):

{
ext: "pdf"
extension: "pdf"
extensionWithDot: ".pdf"
isAudio: false
isImage: false
isJSON: false
isPDF: true
isText: false
isVideo: false
meta: {tag: "past-diagnoses"}
mime: "application/pdf"
mime-type: "application/pdf"
name: "andrey.pdf"
path: "assets/app/uploads/medStorage/XXsrw47TxGvpSNgrf.pdf"
public: false
size: 11626
type: "application/pdf"
userId: "Lvp2fZG3suKGy3oHE"
versions: {original: {…}}
_collectionName: "medicalStorage"
_downloadRoute: "/files/medStorage"
_id: "XXsrw47TxGvpSNgrf"
_storagePath: "assets/app/uploads/medStorage"
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dr-dimitrucommented, Oct 23, 2020

@leprekon91 read docs on .map() — Function to call. It will be called with three arguments: the file, a 0-based index, and cursor itself

I recommend to use .each or .forEach

MedicalStorage.find({ meta: { tag } }).each().map((f) => ({
      name: f.name,
      _id: f._id,
      link:f.link()
    }))
0reactions
dr-dimitrucommented, Nov 20, 2020

@leprekon91 I’m glad you solved it 👍

Please support this project with:

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting url.split is not a function at getFilenameFromURLin ...
I am getting the error above when uploading some of the files in my system... Below is the component using Filepond and React...
Read more >
How to implement multiple file uploads in React?
If not, then head over to React Docs to get started. Setting Up. First, create the React app with the following command. create-react-app...
Read more >
Dealing with multiple files | Just Enough R
Often you will have multiple data files files - for example, ... Using the list.files() function we can list the contents of a...
Read more >
How to process multiple files in Power BI (and ... - YouTube
Processing multiple files in Power BI is a very common request and this can be easily accomplished with a built-in connector.
Read more >
Run your functions from a package file in Azure - Microsoft Learn
Have the Azure Functions runtime run your functions by mounting a deployment package file that contains your function app project files.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found