appwrite / sdk-for-php

[READ-ONLY] Official Appwrite PHP SDK 🐘
https://appwrite.io
BSD 3-Clause "New" or "Revised" License
135 stars 21 forks source link

📚 Documentation: update file with content #11

Open jenniestrongbow opened 2 years ago

jenniestrongbow commented 2 years ago

💭 Description

Hi, after reading your documentation, I could not figure out how to update a file I created earlier with new content. Please help. Thanks

👀 Have you spent some time to check if this issue has been raised before?

🏢 Have you read the Code of Conduct?

eldadfux commented 2 years ago

You can only update the file permissions like this:

<?php

use Appwrite\Client;
use Appwrite\Services\Storage;

$client = new Client();

$client
    ->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
    ->setProject('5df5acd0d48c2') // Your project ID
    ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
;

$storage = new Storage($client);

$result = $storage->updateFile('[FILE_ID]', [], []);

For what you're trying to achieve, you have to delete the old file, and create a new one.

eldadfux commented 2 years ago

More info is available here: https://appwrite.io/docs/server/storage?sdk=php-default#storageUpdateFile

jenniestrongbow commented 2 years ago

Ok, thanks, I saw that page. But It din't make sense to me as you can't upload a file to the file with the same ID.

jenniestrongbow commented 2 years ago

I saw in your example that you entered https://[HOSTNAME_OR_IP]/v1. How do I get https to work with my IP? Should I install certbot? In my experience, it only works with Apache? Which I don't want to use as my 80/443 ports are used by my appwrite. Thanks

Meldiron commented 2 years ago

Ok, thanks, I saw that page. But It didn't make sense to me as you can't upload a file to the file with the same ID.

That is true, the ID will be different. You will have to update your database and set the new ID there. In future, we plan to support Custom IDs that will allow you to set anything as an ID - this will allow you to create a new file with the same ID.

Meldiron commented 2 years ago

I saw in your example that you entered https://[HOSTNAME_OR_IP]/v1. How do I get https to work with my IP? Should I install certbot? In my experience, it only works with Apache? Which I don't want to use as my 80/443 ports are used by my appwrite. Thanks

You could generate custom certificates for your IP address manually (self-signed), but I am not sure how secure that is - browsers might still complain. I recommend you get a domain and set up HTTPS on the domain name.

Let's Encrypt (tool Appwrite uses) issues domain-validated certificates. The certificates must be attached to at least a domain name.

kiloki-official commented 2 years ago

Hi meldiron, thanks for your feedback. I upgraded to version 0.12, so I'll test and see if we can now use custom IDs.

Re. HTTPS, I used Let's Encrypt with a specific domain. Thanks

lohanidamodar commented 2 years ago

@Meldiron is this still relevant? If not please close this.