使用数据库字段动态更改Phoenix App中的URL字符串

时间:2017-11-21 18:16:24

标签: image elixir phoenix-framework

因此,我正在尝试为Google云端存储上托管的图片动态创建公共网址。我是否可以调用文件名的值并将其附加到结构化URL,例如?

import os
filenames = os.listdir()

our_filename = "foo"
cur = 0
cur_filename = "foo"
extension = ".txt"
while(True):
    if (cur_filename) in filenames:
         cur += 1
         cur_filename = our_filename + str(cur) + extension
    else:
         # found a filename that doesn't exist
         f = open(cur_filename,'w')
         f.write(stuff)
         f.close()

<%= img_tag(https://storage.googleapis.com/cods-images/uploads/<% @latestpost.thumbImg %>) %> 与文件名完全匹配的位置?

尝试此操作时,出现以下错误:

@latestpost.thumbImg

如果我执行此操作keyword argument must be followed by space after: https: ,则只会将<img src="https://storage.googleapis.com/cods-images/uploads/@latestpost.thumbImg)" />的值反对添加以创建完整的URL字符串。

1 个答案:

答案 0 :(得分:2)

您应该能够执行以下操作:

<img src="https://storage.googleapis.com/cods-images/uploads/<%= @latestpost.thumbImg %>" />