How to read a file on Windows shared folder from Springboot?

1.4k views Asked by At

I am confused, and googled everything but there's no answer:

I got a excel file stored in somewhere like this on windows, it's a shared file under 'Network':

\\[serverName]\[folderName]\[folderName]\[folderName]\[folderName]\ZNAC.XLSX

It's compulsory that I can only read/download the file here. Everything works fine when I am reading it from local, it both works fine by using SMB or declare the file path directly as an inputstream.

But when I deploy to SAP cloud foundry, it always ends up with FileNotFoundException, and I tried a lot of ways and no change.

I am wondering if the cloud instance is finding the file from internally not externally. But I tried SMB as well, it's not working. I found there is something called 'Volume service' on cloud foundry, but it's not usable in SAP Cloud Foundry.

Any help to make my application able to read an external file from SAP Cloud Foundry?

2

There are 2 answers

6
Suncatcher On

To read a file from an external share you must first create volume service for the corresponding share (NFS or SMB) and start it.

Then you must bind service instance to the CF app like this:

cf bind-service YOUR-APP SERVICE-NAME -c '{"uid":"UID","gid":"GID","mount":"OPTIONAL-MOUNT-PATH","readonly":true}'

The detailed guide is here

https://docs.cloudfoundry.org/devguide/services/using-vol-services.html#smb

0
breadcrumb42 On

SAP Cloud Platform / SAP BTP does not have a service that allows you to access SMB drives. One possibility would be to use a SMB/SAMBA Java client library, configure the Firewall / SAP Cloud Connector accordingly. We once implemented something like that, but there are some challanges on the way.

An other, easier, possibility would be to create an on-premise service (e.g. REST) that allows you to access the files. This service needs to be made available to SCP as well, for example, through SAP API Management.