Here is another question....
I've uploaded a STL file as an additional file for a product. And it gets downloaded in frontend as shown in screen shot.

When I click on that link for STL Downloader, then that STL file will be downloaded successfully. Tried and tested too many times and it worked like a charm. But I don't want that STL file to be downloaded. I want it to be rendered to a STL viewer which I built. That STL viewer is in another web page. So clicking Click here to download associated STL file link should render the STL file to the STL viewer which is in another web page. How can I do it? I don't want users to download STL files because it is the intellectual property of my company.

  • @Marius: Any ideas? Please reply. Jul 11 '14 at 11:37
  • 1
    it's impossible for us to tell you how to render an STL file into a viewer you built and didn't provide us any details about it. is the stl viewer a custom magento extension? is it in a separate project?
    – Alex Dinca
    Jul 11 '14 at 15:30
  • STL viewer is a seperate project. No magento extensions were used for development of STL viewer. Jul 11 '14 at 17:34
  • @alex.ayg: Please reply Jul 14 '14 at 5:33
  • Have you configured the mime-type in your webserver? developer.mozilla.org/en-US/docs/Web/Security/…
    – B00MER
    Jul 14 '14 at 16:50

You can use CURL to achieve this. You need to design two controllers on STL viewer site,

  • one which saves the uploaded file. It should also generate a unique key,assign to this uploaded file and return it.
  • second that accepts the key and loads the relevant STL file in the viewer.

Then add the following code to your Magento. This is a sample code, modify it according to your requirement:

$query="select * from '. $table .' where prod_id =".$product_id;
$file_full_path = Mage::getBaseDir() . "media/product_custom_files". $stl_data['prod_file'];
$post = array('file_contents'=>'@'.$file_full_path);
$target_url = "http://www.yourstlviwersite.com/yourcontroller...";// your first controller path
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
curl_close ($ch);

$result should hold errors OR the key in case of success. In case the file successfully upload, You need to redirect to the second controller of the STL viewer with this key so that it loads the file.

Hope this helps.

  • This is good. But my STL viewer has a separate database where each and every stl file will be saved. So 1st controller for STL viewer won't be needed, I think so Jul 15 '14 at 8:15
  • 1st controller is to upload the file from Magento to STL and assign it a unique key. If you have that STL file already on STL viewer site, then you may don't need this, but still you need a way to relate the STL viewer file with Magento
    – MTM
    Jul 15 '14 at 8:20

You might want to send the file name to the new controller as a parameter in the URL like this: domain.com/stlViewer.php?name=file.stl and in the stl viewer get the file parameter and render it with $_GET["file"] and concatenate like this $path = 'path/to/file'.$_GET['file'].

This has a little security measure since you can hardcore the real path to the file and avoid the customers to directly download it. Its not the safest way to proceed but at least its not super easy to download.

  • Yeah, this is the method which I was trying just now. I am adding a controller in stlviewer to access magento database and get associated stl file with a product and load it into stl viewer when Click here to download associated STL file link is clicked in magento front end. If it works, then I'll be generous and would reward 50 points to you :D Jul 15 '14 at 14:34
  • 1
    If you send the filename as a parameter and you hardcode the path you might be able to avoid using the db i think.
    – mbalparda
    Jul 15 '14 at 14:41
  • I'll try it.... Jul 16 '14 at 4:35
  • Did this worked? Remember to mark this question as resolved.
    – mbalparda
    Jul 19 '14 at 15:33

Awesome example.. I am attempting to integrate Upload STL file and also allow anyone on my Wordpress website to view STL files.. Will this solve my nightmare problem!?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.