pocketbase / js-sdk

PocketBase JavaScript SDK
https://www.npmjs.com/package/pocketbase
MIT License
2.06k stars 122 forks source link

File URL missing Collection id #63

Closed ifigueroap closed 1 year ago

ifigueroap commented 1 year ago

Hi, I'm using pocketbase with a collection that has two fields: name and image. Then I retrieve the image to render it in my site:

const client = new pocketbase(pocketBaseURL);
const imageURL = client.records.getFileUrl(f, f.image, {})
const response = imageURL ? await fetch(imageURL) : null

Now, here is the issue... when running pocketbase in localhost, I get a properly generated file URL: 'http://127.0.0.1:8090/api/files/qoeautlu65mw2cn/utqgwco7b1526ag/sercotec_uH05SslpyV.png'

However, when querying a pocketbase installation hosted in pockethost.io, I get this URL: 'https://bizpro.pockethost.io/api/files//dipod3ppe2zxgwm/sercotec_vBWhz7JbkM.png'

If I access the URL in the browser with the proper id, it works.

ganigeorgiev commented 1 year ago

@ifigueroap What version of PocketBase are you using?

If it is v0.8.0-rc then you have to use the pre-release of the SDK too (aka. the next tag):

npm install pocketbase@next --save

Please note that v0.8.0 has breaking changes and slightly different API. You could find the SDK pre-release in the rc branch - https://github.com/pocketbase/js-sdk/tree/rc.

You can see what are the changes in https://github.com/pocketbase/js-sdk/blob/rc/CHANGELOG.md

ifigueroap commented 1 year ago

I'm seeing a difference in the records as returned by each PocketBase deployment.

From Pockethost (running 0.8.0-rc2 (latest)):

{
    id: 'dipod3ppe2zxgwm',
    created: '2022-11-04 13:29:29.080Z',
    updated: '2022-11-04 13:29:29.080Z',
    collectionId: '3abypxg0x3uvka5',
    collectionName: 'fuente_financiamiento',
    image: 'sercotec_vBWhz7JbkM.png',
    nombre: 'SERCOTEC',
    '@collectionId': '',
    '@collectionName': '',
    '@expand': {}
  }

From Localhost (running version github.com/pocketbase/pocketbase v0.7.10 (from go.mod)):

{
    id: 'utqgwco7b1526ag',
    created: '2022-11-02 18:57:17.289',
    updated: '2022-11-03 23:47:45.841',
    '@collectionId': 'qoeautlu65mw2cn',
    '@collectionName': 'fuente_financiamiento',
    image: 'sercotec_uH05SslpyV.png',
    nombre: 'SERCOTEC',
    '@expand': {}
  }

which boils down to missing data on the @collectionId field.

ifigueroap commented 1 year ago

@ifigueroap What version of PocketBase are you using?

If it is v0.8.0-rc then you have to use the pre-release of the SDK too (aka. the next tag):

npm install pocketbase@next --save

Please note that v0.8.0 has breaking changes and slightly different API. You could find the SDK pre-release in the rc branch - https://github.com/pocketbase/js-sdk/tree/rc.

You can see what are the changes in https://github.com/pocketbase/js-sdk/blob/rc/CHANGELOG.md

I guess then the issue comes from using incompatible versions of PocketBase and js-sdk.

FWIW, I managed to "solve" the issue by doing this ugly hack:

 f["@collectionId"] = f["collectionId"];

But I guess the morale of the story is to not test things using two different versions of PocketBase.

Thanks!

ganigeorgiev commented 1 year ago

@ifigueroap This is expected. In v0.8 the collectionId, colectionName and expand are reserved fields and no longer have the @ prefix (this is why there are duplicated collectionId and @collectionId in the response).

If you use PocketBase v0.7.10 you should use JS SDK v0.7.4.

If you use PocketBase v0.8-rc2 you should use JS SDK v0.8.x.